Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(test): quote workspace_id so the migration fixture stops flaking (#336)

Joseph Mikhail7cf4f989c094
diff --git a/ix-cli/src/cli/__tests__/bootstrap-migration.test.ts b/ix-cli/src/cli/__tests__/bootstrap-migration.test.ts
index a9d0f0d0..13973da7 100644
--- a/ix-cli/src/cli/__tests__/bootstrap-migration.test.ts
+++ b/ix-cli/src/cli/__tests__/bootstrap-migration.test.ts
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
import * as fs from "node:fs";
import * as os from "node:os";
import * as nodePath from "node:path";
+import { parse } from "yaml";
import { ensureWorkspaceIdState } from "../bootstrap.js";
import { workspaceIdForPath } from "../system.js";
@@ -27,10 +28,43 @@ afterEach(() => {
});
function writeConfig(workspaces: object[]) {
+ // workspace_id MUST be quoted. It is 8 hex chars, so ~3.7% of ids are
+ // numeric-looking to YAML. loadConfig's String() normalization round-trips
+ // an integer that reprints identically ("12345678"), but not the other
+ // ~1.6% — "709e7420" parses as Infinity, and "01311916" comes back 1311916
+ // with the leading zero gone — because the original text is lost once the
+ // parser has coerced the value. An unquoted fixture then fires a spurious
+ // migration and fails "does NOT migrate" at that 1.6%.
+ // saveConfig (yaml.stringify) quotes these for real, so quoting here is
+ // also what makes the fixture faithful to a config the CLI actually wrote.
const body = "endpoint: http://localhost:8090\n" +
"workspaces:\n" +
workspaces.map((w: any) =>
- ` - workspace_id: ${w.workspace_id}\n workspace_name: ${w.workspace_name}\n root_path: ${w.root_path}\n default: ${w.default ?? false}\n`).join("");
+ ` - workspace_id: "${w.workspace_id}"\n workspace_name: ${w.workspace_name}\n root_path: ${w.root_path}\n default: ${w.default ?? false}\n`).join("");
+
+ // Enforce it rather than trusting the template. Two checks, deliberately:
+ //
+ // The text check fires 100% of the time, because it does not depend on which
+ // id this run's temp path happened to produce. Checking only the parsed value
+ // would fire solely on ids YAML coerces -- self-diagnosing when it happens,
+ // but still a heisenbug, and silent on the run that reintroduces the quoting
+ // mistake.
+ workspaces.forEach((w: any) => {
+ expect(body, "workspace_id must be quoted in the fixture").toContain(`workspace_id: "${w.workspace_id}"`);
+ });
+
+ // And the parse check, which catches the wider class: any field whose value
+ // YAML would reinterpret (a workspace_name of `true`, `007` or `null`).
+ // Compared strictly, NOT via String() on both sides -- that would cancel out
+ // exactly the boolean and null coercions, the ones with real consequences,
+ // since loadConfig normalizes workspace_id but never workspace_name.
+ const parsed = parse(body) as { workspaces?: { workspace_id: unknown; workspace_name: unknown }[] };
+ (parsed.workspaces ?? []).forEach((w, i) => {
+ expect(typeof w.workspace_id, "workspace_id must survive YAML as a string").toBe("string");
+ expect(w.workspace_id).toBe((workspaces[i] as any).workspace_id);
+ expect(w.workspace_name, "workspace_name must survive YAML unchanged").toBe((workspaces[i] as any).workspace_name);
+ });
+
fs.writeFileSync(nodePath.join(home, ".ix", "config.yaml"), body);
}