Repository navigation
fix(sdk/typescript): kcode binary/path names so the SDK tests can run at all #345
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5de5080
fix(sdk/typescript): rename jcode-prefixed test fixture paths
KooshaPari 3fb0ee8
fix(sdk): merge origin/master to pick up upstream CI gate fixes
KooshaPari 38f6b8b
fix(sdk/typescript): finish the jcode->kcode rename in live smoke paths
KooshaPari 861b3ce
Merge remote-tracking branch 'origin/master' into HEAD
KooshaPari 15ea23f
fix(sdk/typescript): use kcode binary and path names so the SDK tests…
KooshaPari 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,146 @@ | ||
| /** | ||
| * The live smoke scripts are the SDK's only coverage of real `launch()` | ||
| * behaviour: they start an actual instance, drive a turn, and check isolation, | ||
| * credentials, and every documented option. `npm run check` cannot run them, | ||
| * because they need a built binary and a provider login. | ||
| * | ||
| * That gap is how they survived the kcode rebrand still shipping a bare | ||
| * `"jcode"` binary default. `assertKcodePath` rejects that on sight, so | ||
| * `node test/live-options.mjs` threw `cross_product_path` before it checked a | ||
| * single documented option — and the child-daemon knobs were still spelled | ||
| * `JCODE_NO_TELEMETRY` and friends, which the daemon no longer reads, so the | ||
| * instances under test quietly ran with telemetry and memory enabled. | ||
| * | ||
| * These assertions run the guard against the values the scripts actually ship, | ||
| * so the next rename fails here instead of in someone's terminal. | ||
| */ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { assertKcodePath } from "../dist/product.js"; | ||
|
|
||
| const here = path.dirname(fileURLToPath(import.meta.url)); | ||
| const repoRoot = path.resolve(here, "../../.."); | ||
|
|
||
| const liveScripts = fs | ||
| .readdirSync(here) | ||
| .filter((name) => name.startsWith("live-") && name.endsWith(".mjs")) | ||
| .sort(); | ||
|
|
||
| /** `process.argv[2] ?? "kcode"`, and the `path.resolve(...)` form around it. */ | ||
| const DEFAULT_BINARY = /process\.argv\[2\]\s*\?\?\s*"([^"]+)"/u; | ||
| const TEST_BINARY_ENV = /\bKCODE_SDK_TEST_BINARY\b/u; | ||
|
|
||
| function read(name: string): string { | ||
| return fs.readFileSync(path.join(here, name), "utf8"); | ||
| } | ||
|
|
||
| function defaultBinaryOf(source: string): string | undefined { | ||
| return DEFAULT_BINARY.exec(source)?.[1]; | ||
| } | ||
|
|
||
| /** Strip shell comments so prose explaining the old name is not read as code. */ | ||
| function codeLines(script: string): string { | ||
| return script | ||
| .split("\n") | ||
| .filter((line) => !line.trimStart().startsWith("#")) | ||
| .join("\n"); | ||
| } | ||
|
|
||
| /** | ||
| * `assertKcodePath` resolves against the cwd and then walks up to the nearest | ||
| * existing ancestor, so its verdict also depends on the directory the repo was | ||
| * cloned into. Resolve from a scratch directory so these assertions are about | ||
| * the value a script ships rather than about where someone cloned the repo. | ||
| */ | ||
| function assertGuardAccepts(label: string, candidate: string): void { | ||
| const scratch = fs.mkdtempSync(path.join(os.tmpdir(), "kcode-guard-probe-")); | ||
| const original = process.cwd(); | ||
| try { | ||
| process.chdir(scratch); | ||
| assert.doesNotThrow( | ||
| () => assertKcodePath(candidate), | ||
| `${label} hands assertKcodePath "${candidate}", which it rejects as a cross-product path`, | ||
| ); | ||
| } finally { | ||
| process.chdir(original); | ||
| fs.rmSync(scratch, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| test("the live smoke scripts are all discovered", () => { | ||
| // Guards the filter itself: an empty or near-empty list would make every | ||
| // assertion below vacuously true, which is how a rename could pass again. | ||
| assert.ok( | ||
| liveScripts.length >= 8, | ||
| `expected the full live-* cohort, found only ${liveScripts.length}: ${liveScripts.join(", ")}`, | ||
| ); | ||
| }); | ||
|
|
||
| test("exactly one live script takes its binary from the environment", () => { | ||
| // live-tools.mjs is opt-in and insists on an absolute path; the rest either | ||
| // default to a bare name or connect to a bridge test_sdk_e2e.sh started for | ||
| // them. Pinning the count keeps a new env-driven script from appearing with | ||
| // nobody checking the knob it reads. | ||
| assert.deepEqual(liveScripts.filter((name) => TEST_BINARY_ENV.test(read(name))), ["live-tools.mjs"]); | ||
| }); | ||
|
|
||
| for (const name of liveScripts) { | ||
| test(`${name} ships a default binary the guard accepts`, () => { | ||
| const source = read(name); | ||
| const fallback = defaultBinaryOf(source); | ||
| // A script with no argv default is driven by test_sdk_e2e.sh against a | ||
| // bridge it already started (live-turn, live-control, live-capabilities) | ||
| // and never names a binary, so there is no default left to get wrong. | ||
| if (fallback !== undefined) assertGuardAccepts(name, fallback); | ||
| }); | ||
|
|
||
| test(`${name} reads and sets only KCODE_-prefixed knobs`, () => { | ||
| const legacy = [...read(name).matchAll(/\bJCODE_[A-Z_]+\b/gu)].map((m) => m[0]); | ||
| assert.deepEqual( | ||
| [...new Set(legacy)].sort(), | ||
| [], | ||
| `${name} still uses pre-rebrand env knobs the daemon no longer reads`, | ||
| ); | ||
| }); | ||
|
|
||
| test(`${name} creates its scratch directories under a kcode prefix`, () => { | ||
| // Only the ones that are actually handed to the SDK: a temp dir becomes an | ||
| // instance home or a working directory, both of which go through the guard. | ||
| for (const prefix of [...read(name).matchAll(/mkdtemp(?:Sync)?\(\s*path\.join\([^,]+,\s*"([^"]+)"/gu)].map((m) => m[1])) { | ||
| assertGuardAccepts(`${name} temp prefix`, prefix); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| test("the e2e driver builds the kcode binary, not the pre-rebrand name", () => { | ||
| const driver = codeLines(fs.readFileSync(path.join(repoRoot, "scripts/test_sdk_e2e.sh"), "utf8")); | ||
| assert.match(driver, /cargo build --profile selfdev -p kcode --bin kcode\b/u); | ||
| assert.doesNotMatch(driver, /--bin jcode(?![\w-])/u, "the jcode bin target no longer exists in this fork"); | ||
| }); | ||
|
|
||
| test("the e2e driver's socket path is one the guard accepts", () => { | ||
| const driver = fs.readFileSync(path.join(repoRoot, "scripts/test_sdk_e2e.sh"), "utf8"); | ||
| const socket = /socket="\$\{TMPDIR:-\/tmp\}\/([^"$]*)/u.exec(driver)?.[1]; | ||
| assert.ok(socket, "could not read the socket template out of test_sdk_e2e.sh"); | ||
| assertGuardAccepts("test_sdk_e2e.sh socket", socket); | ||
| }); | ||
|
|
||
| test("the documented opt-in commands name a binary this fork builds", () => { | ||
| const docs = [ | ||
| path.join(repoRoot, "sdk/typescript/README.md"), | ||
| path.join(repoRoot, "docs/dev/GUY_ISSUE_ACCEPTANCE.md"), | ||
| ]; | ||
| for (const doc of docs) { | ||
| const source = fs.readFileSync(doc, "utf8"); | ||
| const stale = [...source.matchAll(/live-[a-z-]+\.mjs\s+\.\/target\/selfdev\/jcode\b/gu)]; | ||
| assert.deepEqual( | ||
| stale.map((m) => m[0]), | ||
| [], | ||
| `${path.relative(repoRoot, doc)} still tells a reader to run a jcode binary that no longer exists`, | ||
| ); | ||
| } | ||
| }); | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: When
os.tmpdir()is under.jcodeorjcode, the scratch cwd makes valid relative candidates fail the guard, causing these tests to fail spuriously.Assessment: 🟠
Major· 🔁Occurrence: Rarely· 🏷️Possible bugPrompt for AI Agent 🤖