File size: 1,720 Bytes
f778c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Migration context tests cover report directory naming and timestamp fallback behavior.
import path from "node:path";
import { describe, expect, it } from "vitest";
import { buildMigrationReportDir, resolveMigrationTargetAgentId } from "./context.js";

describe("migration context helpers", () => {
  it("builds report directories with filename-safe timestamps", () => {
    const now = Date.parse("2026-02-23T12:34:56.000Z");
    expect(buildMigrationReportDir("codex", "/state", now)).toBe(
      path.join("/state", "migration", "codex", "2026-02-23T12-34-56.000Z"),
    );
  });

  it("falls back instead of throwing for out-of-range report timestamps", () => {
    expect(buildMigrationReportDir("codex", "/state", 9_000_000_000_000_000)).toMatch(
      /[/\\]migration[/\\]codex[/\\]\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}Z$/,
    );
  });

  it("normalizes and validates an explicit migration target agent", () => {
    const config = {
      agents: {
        list: [{ id: "main", default: true }, { id: "research" }],
      },
    };

    expect(resolveMigrationTargetAgentId(config, "Research")).toBe("research");
    expect(() => resolveMigrationTargetAgentId(config, "research/../main")).toThrow(
      'Invalid agent id "research/../main"',
    );
    expect(() => resolveMigrationTargetAgentId(config, "missing")).toThrow(
      'Unknown agent id "missing"',
    );
  });

  it("keeps the configured default when no migration target is supplied", () => {
    expect(resolveMigrationTargetAgentId({}, undefined)).toBeUndefined();
  });

  it("rejects an explicitly blank migration target", () => {
    expect(() => resolveMigrationTargetAgentId({}, "")).toThrow("--agent must not be blank");
  });
});