Repository navigation
fix(cli): preserve newlines in generated Compose values #1708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rohitg00
merged 7 commits into
rohitg00:main
from
zhichao-poper:fix/compose-multiline-values
Nov 9, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a7f8a0
fix(cli): preserve newlines in generated Compose values
zhichao-poper 76e5ddf
fix(cli): escape C1 characters in Compose values
zhichao-poper 764c015
test(cli): verify Compose C1 values with the pinned engine
zhichao-poper b443f76
ci: run the Compose C1 regression in the release gate
zhichao-poper acc85aa
test(cli): harden Compose probe setup and dependency resolution
zhichao-poper 45cd4f3
Merge remote-tracking branch 'origin/main' into pr-1708
rohitg00 066736b
fix(cli): escape line separators and publish the Compose probe snapsh…
rohitg00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { spawn, spawnSync, type ChildProcess } from "node:child_process"; | ||
| import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { createServer } from "node:net"; | ||
| import { createRequire } from "node:module"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { pathToFileURL } from "node:url"; | ||
| import { setTimeout as sleep } from "node:timers/promises"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { composeNamespace, writeWorkerCompose } from "../src/cli/compose-project.js"; | ||
| import { III_PINNED_VERSION } from "../src/version.js"; | ||
|
|
||
| const engine = process.env.AGENTMEMORY_TEST_III; | ||
| const version = engine ? spawnSync(engine, ["--version"], { encoding: "utf8", timeout: 3000 }) : null; | ||
| const available = version?.status === 0 && version.stdout.trim() === III_PINNED_VERSION; | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
|
||
| const skipped = !available || process.platform === "win32" || process.env.AGENTMEMORY_SKIP_LIVE_TESTS === "1"; | ||
| if (process.env.AGENTMEMORY_REQUIRE_LIVE_TESTS === "1" && skipped) { | ||
| throw new Error(`Required Compose C1 test needs iii ${III_PINNED_VERSION} and live tests enabled on macOS or Linux`); | ||
| } | ||
|
|
||
| async function freePort(): Promise<number> { | ||
| const server = createServer(); | ||
| await new Promise<void>((accept, reject) => { | ||
| server.once("error", reject); | ||
| server.listen(0, "127.0.0.1", accept); | ||
| }); | ||
| const port = (server.address() as { port: number }).port; | ||
| await new Promise<void>((accept) => server.close(() => accept())); | ||
| return port; | ||
| } | ||
|
|
||
| async function stop(child: ChildProcess): Promise<void> { | ||
| if (child.exitCode !== null || child.signalCode !== null) return; | ||
| const exited = new Promise<void>((accept) => child.once("exit", () => accept())); | ||
| child.kill("SIGINT"); | ||
| const result = await Promise.race([exited.then(() => true), sleep(5000).then(() => false)]); | ||
| if (!result && child.pid) { | ||
| try { process.kill(-child.pid, "SIGKILL"); } catch {} | ||
| await exited; | ||
| } | ||
| } | ||
|
|
||
| describe.skipIf(skipped)("pinned Compose C1 environment round trip", () => { | ||
| it("delivers all C1 characters and line breaks unchanged to a real worker", async () => { | ||
| const root = mkdtempSync(join(tmpdir(), "agentmemory-compose-c1-")); | ||
| let child: ChildProcess | undefined; | ||
| try { | ||
| const pkg = join(root, "worker"); | ||
| const snapshot = join(root, "received.json"); | ||
| mkdirSync(join(pkg, "dist"), { recursive: true }); | ||
| const value = `first\n${String.fromCharCode(...Array.from({ length: 32 }, (_, i) => 0x80 + i))}\u2028\u2029\r\nquote'\"\\\tend\n`; | ||
| const sdk = pathToFileURL(createRequire(import.meta.url).resolve("iii-sdk")).href; | ||
| writeFileSync(join(pkg, "dist/index.mjs"), ` | ||
| import sdkModule from ${JSON.stringify(sdk)}; | ||
| import { renameSync, writeFileSync } from "node:fs"; | ||
| const { registerWorker } = sdkModule; | ||
| const worker = registerWorker(process.env.III_URL, { workerName: "agentmemory" }); | ||
| worker.registerFunction("test::env", async () => process.env.OPENAI_BASE_URL); | ||
| writeFileSync(${JSON.stringify(`${snapshot}.tmp`)}, JSON.stringify(process.env.OPENAI_BASE_URL)); | ||
| renameSync(${JSON.stringify(`${snapshot}.tmp`)}, ${JSON.stringify(snapshot)}); | ||
| `); | ||
| const ports = { restPort: await freePort(), viewerPort: await freePort(), enginePort: await freePort() }; | ||
| const project = writeWorkerCompose({ | ||
| ports, projectRoot: pkg, dataDir: join(root, "data"), homeDir: join(root, "home"), | ||
| nodeBin: process.execPath, workerEnvironment: { OPENAI_BASE_URL: value }, | ||
| }); | ||
| const header = project.text.slice(0, project.text.indexOf("containers:\n")); | ||
| const app = project.text.slice(project.text.indexOf(" agentmemory:\n")) | ||
| .replace(" start_after: [state, http]", " start_after: []"); | ||
| writeFileSync(project.file, `${header}containers:\n${app}`); | ||
| child = spawn(engine!, ["compose", "--namespace", composeNamespace(ports.restPort), "--up", "--file", project.file], { | ||
| env: { PATH: process.env.PATH, HOME: join(root, "home"), USERPROFILE: join(root, "home"), | ||
| III_COMPOSE_STATE_DIR: project.stateDir, III_TELEMETRY_ENABLED: "false", III_BUNDLE_WORKERS_DISABLED: "1", RUST_LOG: "error" }, | ||
| detached: true, stdio: ["ignore", "ignore", "pipe"], | ||
| }); | ||
| let logs = ""; | ||
| child.stderr?.on("data", (chunk) => { logs = `${logs}${chunk}`.slice(-16000); }); | ||
| const deadline = Date.now() + 20000; | ||
| while (Date.now() < deadline) { | ||
| try { | ||
| expect(JSON.parse(readFileSync(snapshot, "utf8"))).toBe(value); | ||
| return; | ||
| } catch (error) { | ||
| if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; | ||
| } | ||
| if (child.exitCode !== null || child.signalCode !== null) throw new Error(`Compose exited before the worker received its value: ${logs}`); | ||
| await sleep(50); | ||
| } | ||
| throw new Error(`Worker environment snapshot timed out: ${logs}`); | ||
| } finally { | ||
| if (child) await stop(child); | ||
| rmSync(root, { recursive: true, force: true }); | ||
| } | ||
| }, 30000); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.