Skip to content

Commit 2540a02

Browse files
committed
merge: PR lidge-jun#304 kiro clean-text-EOF + test isolation (local stack, review doc 050) — conflicts resolved to PR-side which already contains upstream dev
2 parents e281090 + 8af2194 commit 2540a02

17 files changed

Lines changed: 169 additions & 60 deletions

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"dev:proxy": "bun run src/cli/index.ts start",
3737
"dev:gui": "cd gui && bun run dev",
3838
"start": "bun run src/cli/index.ts start",
39-
"test": "bun test --isolate ./tests/",
39+
"test": "bun scripts/test.ts",
4040
"typecheck": "bun x tsc --noEmit",
4141
"privacy:scan": "bun scripts/privacy-scan.ts",
4242
"generate:jawcode-metadata": "bun scripts/generate-jawcode-metadata.ts",

‎scripts/test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
2+
import { tmpdir } from "node:os";
3+
import { join } from "node:path";
4+
5+
export interface IsolatedTestEnvironment {
6+
root: string;
7+
env: Record<string, string | undefined>;
8+
cleanup(): void;
9+
}
10+
11+
export function createIsolatedTestEnvironment(
12+
baseEnv: Record<string, string | undefined> = process.env,
13+
): IsolatedTestEnvironment {
14+
const root = mkdtempSync(join(tmpdir(), "opencodex-test-"));
15+
const opencodexHome = join(root, ".opencodex");
16+
const codexHome = join(root, ".codex");
17+
mkdirSync(opencodexHome, { recursive: true });
18+
mkdirSync(codexHome, { recursive: true });
19+
20+
return {
21+
root,
22+
env: {
23+
...baseEnv,
24+
HOME: root,
25+
USERPROFILE: root,
26+
OPENCODEX_HOME: opencodexHome,
27+
CODEX_HOME: codexHome,
28+
},
29+
cleanup() {
30+
rmSync(root, { recursive: true, force: true });
31+
},
32+
};
33+
}
34+
35+
if (import.meta.main) {
36+
const isolated = createIsolatedTestEnvironment();
37+
try {
38+
const requestedTests = process.argv.slice(2);
39+
const child = Bun.spawnSync(
40+
[process.execPath, "test", "--isolate", ...(requestedTests.length > 0 ? requestedTests : ["./tests/"])],
41+
{
42+
env: isolated.env,
43+
stdin: "inherit",
44+
stdout: "inherit",
45+
stderr: "inherit",
46+
},
47+
);
48+
process.exitCode = child.exitCode ?? 1;
49+
} finally {
50+
isolated.cleanup();
51+
}
52+
}

‎src/adapters/kiro.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,14 @@ async function* parseKiroAttempt(
846846
...(contextWindow ? { configuredContextWindow: contextWindow } : {}),
847847
});
848848
}
849+
debugProviderDiagnostic("kiro", "attempt_complete", {
850+
mode,
851+
sawText,
852+
sawReasoning,
853+
sawRealTool,
854+
completionCalls,
855+
assistantChars: assistantText.length,
856+
});
849857

850858
if (mode === "text_fallback") {
851859
if (completionAnswer !== undefined) {
@@ -909,7 +917,23 @@ async function* parseKiroAttempt(
909917
terminal: { type: "done", usage: finalUsage, endTurn: false, ...(finalProviderState ? { providerState: finalProviderState } : {}) },
910918
};
911919
}
912-
if (mode === "required" && (sawText || sawReasoning)) {
920+
// A clean Smithy EOF after ordinary assistant text is a complete answer even when the
921+
// private completion tool was advertised. Replaying that answer through a second Kiro
922+
// request adds latency and can hang an otherwise-finished Codex turn if the retry stalls.
923+
// Reasoning-only output still needs the bounded fallback because it has no user-facing text.
924+
if (mode === "required" && sawText) {
925+
return {
926+
assistantText,
927+
sawReasoning,
928+
terminal: {
929+
type: "done",
930+
usage: finalUsage,
931+
endTurn: true,
932+
...(finalProviderState ? { providerState: finalProviderState } : {}),
933+
},
934+
};
935+
}
936+
if (mode === "required" && sawReasoning) {
913937
return { assistantText, sawReasoning, needsFallback: true, usage: finalUsage, providerState: finalProviderState };
914938
}
915939
if (!sawText && !sawReasoning) {

‎src/codex/home.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ function readProcVersion(): string | null {
7979
}
8080

8181
export function isWslRuntime(deps: CodexHomeDeps = {}): boolean {
82+
if ((deps.platform ?? process.platform) !== "linux") return false;
8283
const env = deps.env ?? process.env;
8384
if (env.WSL_DISTRO_NAME || env.WSL_INTEROP) return true;
84-
if ((deps.platform ?? process.platform) !== "linux") return false;
8585
const version = `${deps.release ?? ""}\n${deps.procVersion ?? readProcVersion() ?? ""}`;
8686
return /microsoft|wsl/i.test(version);
8787
}

‎structure/04_transports-and-sidecars.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ the watchdog.
8484
The web-search loop requests `stream: true` for every routed-model iteration, but buffers the events
8585
needed to decide whether to intercept a synthetic search call. Text explicitly phased as
8686
`commentary` is safe to forward live because it cannot terminate the turn; this keeps Kiro's
87-
progress visible while its bounded completion retry runs. Synthetic search calls, real tool calls,
87+
progress visible. A clean Kiro stream EOF after user-facing text completes directly; reasoning-only
88+
output still gets one bounded completion retry. Synthetic search calls, real tool calls,
8889
and terminal events remain buffered until the iteration validates. Only the first iteration's final
8990
response headers/status and any 429 key rotations are handled eagerly. A failure before downstream
9091
SSE starts returns non-2xx JSON; once headers have started the final response, a generation failure

‎tests/claude-management-api.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ beforeEach(() => {
3232
port: 0,
3333
defaultProvider: "mock",
3434
providers: {
35-
mock: { adapter: "openai-chat", baseUrl: "http://127.0.0.1:1/v1", apiKey: "k", allowPrivateNetwork: true, models: ["test-model"] },
35+
mock: { adapter: "openai-chat", baseUrl: "http://127.0.0.1:1/v1", apiKey: "k", allowPrivateNetwork: true, liveModels: false, models: ["test-model"] },
3636
},
3737
} as OcxConfig);
3838
});

‎tests/claude-messages-endpoint.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,11 @@ test("fetchWithHeaderDeadline classifies expiry as timeout and still clears exac
263263
});
264264

265265
test("native Anthropic passthrough returns 502 when the upstream connection is refused (reject-path activation)", async () => {
266+
const closed = Bun.serve({ port: 0, fetch: () => new Response() });
267+
const closedOrigin = closed.url.toString().replace(/\/$/, "");
268+
closed.stop(true);
266269
const config = mockConfig("http://127.0.0.1:1/v1", {
267-
anthropicBaseUrl: "http://127.0.0.1:9",
270+
anthropicBaseUrl: closedOrigin,
268271
});
269272
config.connectTimeoutMs = 60_000;
270273
saveConfig(config);

‎tests/claude-models-discovery.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function configWithStaticModels(claudeCode?: OcxConfig["claudeCode"]): OcxConfig
3737
baseUrl: "http://127.0.0.1:1/v1",
3838
apiKey: "k",
3939
allowPrivateNetwork: true,
40+
liveModels: false,
4041
models: ["test-model", "other-model"],
4142
},
4243
},

‎tests/claude-native-passthrough.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ function cfg(anthropicBaseUrl: string, extraClaude?: Record<string, unknown>): O
5555
port: 0,
5656
defaultProvider: "mock",
5757
providers: {
58-
mock: { adapter: "openai-chat", baseUrl: "http://127.0.0.1:1/v1", apiKey: "k", allowPrivateNetwork: true, models: ["test-model"] },
58+
mock: { adapter: "openai-chat", baseUrl: "http://127.0.0.1:1/v1", apiKey: "k", allowPrivateNetwork: true, liveModels: false, models: ["test-model"] },
5959
},
60+
connectTimeoutMs: 250,
6061
claudeCode: { anthropicBaseUrl, ...extraClaude },
6162
} as OcxConfig;
6263
}

‎tests/cli-account.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ describe("ocx account CLI (issue #180 matrix)", () => {
448448
test("10: proxy-down exits one with ocx start and ensure guidance", async () => {
449449
const result = await run(
450450
["list"],
451-
{ baseUrl: "http://127.0.0.1:1", loadConfigImpl: fixtureConfig },
451+
{
452+
baseUrl: "http://127.0.0.1:1",
453+
loadConfigImpl: fixtureConfig,
454+
fetchImpl: async () => { throw new TypeError("connection refused"); },
455+
},
452456
);
453457

454458
expect(result.code).toBe(1);

0 commit comments

Comments
 (0)