kodingo-cli 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/branchSettlement.test.js +295 -0
- package/dist/__tests__/deepScanConsentOrdering.test.js +113 -0
- package/dist/__tests__/deepScanHookBranchGate.test.js +136 -0
- package/dist/__tests__/deepScanLocal.test.js +65 -0
- package/dist/__tests__/deepScanNetworkFlows.test.js +154 -0
- package/dist/__tests__/initCoverageShortcut.test.js +54 -0
- package/dist/__tests__/installHook.test.js +62 -0
- package/dist/__tests__/pollAndOutcome.test.js +89 -0
- package/dist/__tests__/repo-identity.test.js +32 -0
- package/dist/__tests__/settleAlreadyCompleteProject.test.js +353 -0
- package/dist/cli.js +2 -1
- package/dist/commands/deep-scan.js +542 -8
- package/dist/commands/init.js +87 -23
- package/dist/commands/install-hook.js +23 -8
- package/dist/utils/repo-identity.js +23 -9
- package/package.json +2 -2
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** Validation fixtures only; no production or customer identifiers.
|
|
7
|
+
* Exercises the network-facing branch-settlement/poll/reconcile flow with a
|
|
8
|
+
* hand-rolled fetch stub (no real HTTP, no database) — matching this repo's
|
|
9
|
+
* own dry-run test's pattern of using a real temporary git repo for git
|
|
10
|
+
* plumbing while keeping every network call mocked.
|
|
11
|
+
*/
|
|
12
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
13
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
14
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
15
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
+
const node_child_process_1 = require("node:child_process");
|
|
17
|
+
const node_test_1 = require("node:test");
|
|
18
|
+
const deep_scan_1 = require("../commands/deep-scan");
|
|
19
|
+
function fakeFetch(responses) {
|
|
20
|
+
const calls = [];
|
|
21
|
+
const fn = async (url, init) => {
|
|
22
|
+
calls.push({ url, init });
|
|
23
|
+
const next = responses.shift();
|
|
24
|
+
if (!next)
|
|
25
|
+
throw new Error(`deepScanNetworkFlows test: no mock response left for ${url}`);
|
|
26
|
+
return { ok: (next.status ?? 200) < 300, status: next.status ?? 200, json: async () => next.body };
|
|
27
|
+
};
|
|
28
|
+
return { fn, calls };
|
|
29
|
+
}
|
|
30
|
+
function withFetch(responses, run) {
|
|
31
|
+
const original = global.fetch;
|
|
32
|
+
const { fn, calls } = fakeFetch(responses);
|
|
33
|
+
global.fetch = fn;
|
|
34
|
+
return run(calls).finally(() => { global.fetch = original; });
|
|
35
|
+
}
|
|
36
|
+
function makeRepo(branch = "main") {
|
|
37
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-branch-settle-"));
|
|
38
|
+
(0, node_child_process_1.execFileSync)("git", ["init", "-q", "-b", branch, root]);
|
|
39
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.email", "test@example.invalid"]);
|
|
40
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.name", "Validation Test"]);
|
|
41
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "add", "origin", "git@github.com:org/repo.git"]);
|
|
42
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "a.ts"), "export const a = 1;\n");
|
|
43
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "add", "."]);
|
|
44
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "commit", "-qm", "fixture"]);
|
|
45
|
+
return root;
|
|
46
|
+
}
|
|
47
|
+
(0, node_test_1.describe)("settleTrackedBranch", () => {
|
|
48
|
+
(0, node_test_1.it)("proceeds silently on a match, making only the one check call", async () => {
|
|
49
|
+
const root = makeRepo("main");
|
|
50
|
+
const result = await withFetch([{ body: { outcome: "match", trackedBranch: "main" } }], async (calls) => {
|
|
51
|
+
const r = await (0, deep_scan_1.settleTrackedBranch)({ apiUrl: "https://api.test", token: "tok", root, repository: "org/repo", repositoryName: "repo", branch: "main", yes: false });
|
|
52
|
+
strict_1.default.equal(calls.length, 1);
|
|
53
|
+
return r;
|
|
54
|
+
});
|
|
55
|
+
strict_1.default.deepEqual(result, { recorded: false, held: false, trackedBranch: "main" });
|
|
56
|
+
});
|
|
57
|
+
(0, node_test_1.it)("reports a mismatch as held, without ever attempting to record over it", async () => {
|
|
58
|
+
const root = makeRepo("feature/x");
|
|
59
|
+
const result = await withFetch([{ body: { outcome: "mismatch", trackedBranch: "main" } }], (calls) => (0, deep_scan_1.settleTrackedBranch)({ apiUrl: "https://api.test", token: "tok", root, repository: "org/repo", repositoryName: "repo", branch: "feature/x", yes: false }).then((r) => { strict_1.default.equal(calls.length, 1); return r; }));
|
|
60
|
+
strict_1.default.deepEqual(result, { recorded: false, held: true, trackedBranch: "main" });
|
|
61
|
+
});
|
|
62
|
+
(0, node_test_1.it)("holds with a plain message when none is tracked and non-interactive input declines the prompt", async () => {
|
|
63
|
+
const root = makeRepo("main");
|
|
64
|
+
const result = await withFetch([{ body: { outcome: "none", trackedBranch: null } }], (calls) => (0, deep_scan_1.settleTrackedBranch)({ apiUrl: "https://api.test", token: "tok", root, repository: "org/repo", repositoryName: "repo", branch: "main", yes: false }).then((r) => { strict_1.default.equal(calls.length, 1); return r; }));
|
|
65
|
+
strict_1.default.deepEqual(result, { recorded: false, held: true, trackedBranch: null });
|
|
66
|
+
});
|
|
67
|
+
(0, node_test_1.it)("--yes records a branch when none is tracked and the checkout matches the remote's default branch", async () => {
|
|
68
|
+
const root = makeRepo("main");
|
|
69
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
70
|
+
const result = await withFetch([{ body: { outcome: "none", trackedBranch: null } }, { body: { outcome: "recorded", trackedBranch: "main" } }], (calls) => (0, deep_scan_1.settleTrackedBranch)({ apiUrl: "https://api.test", token: "tok", root, repository: "org/repo", repositoryName: "repo", branch: "main", yes: true }).then((r) => {
|
|
71
|
+
strict_1.default.equal(calls.length, 2);
|
|
72
|
+
const secondBody = JSON.parse(calls[1].init.body);
|
|
73
|
+
strict_1.default.equal(secondBody.record, true);
|
|
74
|
+
strict_1.default.ok(typeof secondBody.attributedBy === "string" && secondBody.attributedBy.length > 0);
|
|
75
|
+
return r;
|
|
76
|
+
}));
|
|
77
|
+
strict_1.default.deepEqual(result, { recorded: true, held: false, trackedBranch: "main" });
|
|
78
|
+
});
|
|
79
|
+
(0, node_test_1.it)("--yes refuses with a non-zero-exit-causing error when the default branch cannot be determined", async () => {
|
|
80
|
+
const root = makeRepo("main");
|
|
81
|
+
// Point origin at a path that doesn't exist, locally — resolveDefaultBranch's
|
|
82
|
+
// `git remote show origin` fallback then fails fast, offline, rather than
|
|
83
|
+
// attempting a real network connection to the fake git@github.com remote.
|
|
84
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "set-url", "origin", "/nonexistent/kodingo-test-remote"]);
|
|
85
|
+
await withFetch([{ body: { outcome: "none", trackedBranch: null } }], async () => {
|
|
86
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.settleTrackedBranch)({ apiUrl: "https://api.test", token: "tok", root, repository: "org/repo", repositoryName: "repo", branch: "main", yes: true }), /could not be determined/);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
(0, node_test_1.it)("--yes refuses when the checkout does not match the remote's default branch", async () => {
|
|
90
|
+
const root = makeRepo("feature/x");
|
|
91
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
92
|
+
await withFetch([{ body: { outcome: "none", trackedBranch: null } }], async () => {
|
|
93
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.settleTrackedBranch)({ apiUrl: "https://api.test", token: "tok", root, repository: "org/repo", repositoryName: "repo", branch: "feature/x", yes: true }), /does not match the remote's default branch/);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
(0, node_test_1.describe)("resolveDefaultBranch", () => {
|
|
98
|
+
(0, node_test_1.it)("returns null when neither the local ref nor the remote-show fallback can determine it", async () => {
|
|
99
|
+
const root = makeRepo("main");
|
|
100
|
+
// A local path that doesn't exist — `git remote show origin` fails fast,
|
|
101
|
+
// offline, exactly like a genuinely unreachable remote would, without this
|
|
102
|
+
// test ever attempting a real network connection.
|
|
103
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "set-url", "origin", "/nonexistent/kodingo-test-remote"]);
|
|
104
|
+
strict_1.default.equal(await (0, deep_scan_1.resolveDefaultBranch)(root), null);
|
|
105
|
+
});
|
|
106
|
+
(0, node_test_1.it)("reads the branch name from refs/remotes/origin/HEAD when present", async () => {
|
|
107
|
+
const root = makeRepo("main");
|
|
108
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
109
|
+
strict_1.default.equal(await (0, deep_scan_1.resolveDefaultBranch)(root), "main");
|
|
110
|
+
});
|
|
111
|
+
(0, node_test_1.it)("falls back to `git remote show origin` when refs/remotes/origin/HEAD isn't set", async () => {
|
|
112
|
+
// A real, local (no network) git repo standing in for the remote — this
|
|
113
|
+
// exercises the actual `git remote show origin` fallback path, not a stub.
|
|
114
|
+
const remoteRoot = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-fake-remote-"));
|
|
115
|
+
(0, node_child_process_1.execFileSync)("git", ["init", "-q", "-b", "trunk", remoteRoot]);
|
|
116
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", remoteRoot, "config", "user.email", "test@example.invalid"]);
|
|
117
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", remoteRoot, "config", "user.name", "Validation Test"]);
|
|
118
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(remoteRoot, "f.txt"), "hi\n");
|
|
119
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", remoteRoot, "add", "."]);
|
|
120
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", remoteRoot, "commit", "-qm", "fixture"]);
|
|
121
|
+
const root = makeRepo("main");
|
|
122
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "set-url", "origin", remoteRoot]);
|
|
123
|
+
// No refs/remotes/origin/HEAD set — the first strategy has nothing to read.
|
|
124
|
+
strict_1.default.equal(await (0, deep_scan_1.resolveDefaultBranch)(root), "trunk");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
(0, node_test_1.describe)("settleAndReconcile — the held-then-applied path", () => {
|
|
128
|
+
(0, node_test_1.it)("records the tracked branch and automatically reapplies a held scan at the same commit, without a new upload", async () => {
|
|
129
|
+
const root = makeRepo("main");
|
|
130
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
131
|
+
const commitSha = (0, node_child_process_1.execFileSync)("git", ["-C", root, "rev-parse", "HEAD"], { encoding: "utf8" }).trim();
|
|
132
|
+
const logs = [];
|
|
133
|
+
const originalLog = console.log;
|
|
134
|
+
console.log = (...args) => { logs.push(args.join(" ")); };
|
|
135
|
+
try {
|
|
136
|
+
const result = await withFetch([
|
|
137
|
+
{ body: { outcome: "none", trackedBranch: null } },
|
|
138
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } },
|
|
139
|
+
{ body: { lastScan: { id: "scan-1", commitSha, applied: false, reason: "branch_mismatch:main:unregistered", entityCount: 0, edgeCount: 0, fileCount: 0 } } },
|
|
140
|
+
{ body: { scanId: "scan-1", applied: true, reason: "clean_tracked_branch", entityCount: 2, evidenceCount: 3, edgeCount: 1, fileCount: 1 } },
|
|
141
|
+
], (calls) => (0, deep_scan_1.settleAndReconcile)({ apiUrl: "https://api.test", token: "tok", root, yes: true }).then((r) => { strict_1.default.equal(calls.length, 4); return r; }));
|
|
142
|
+
strict_1.default.deepEqual(result, { handled: true });
|
|
143
|
+
strict_1.default.ok(logs.some((line) => /Deep scan applied: 2 entities, 1 edges, 1 files/.test(line)), `expected an applied summary line, got: ${JSON.stringify(logs)}`);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
console.log = originalLog;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
(0, node_test_1.it)("does not attempt reconciliation when the branch was already tracked (match — nothing recorded)", async () => {
|
|
150
|
+
const root = makeRepo("main");
|
|
151
|
+
const result = await withFetch([{ body: { outcome: "match", trackedBranch: "main" } }], (calls) => (0, deep_scan_1.settleAndReconcile)({ apiUrl: "https://api.test", token: "tok", root, yes: false }).then((r) => { strict_1.default.equal(calls.length, 1); return r; }));
|
|
152
|
+
strict_1.default.deepEqual(result, { handled: false });
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** Validation fixtures only; no production or customer identifiers.
|
|
7
|
+
* Covers the product rule: a project whose read is complete (from any
|
|
8
|
+
* source, any commit) does not need another local scan — and --force
|
|
9
|
+
* always overrides that shortcut.
|
|
10
|
+
*/
|
|
11
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
12
|
+
const node_test_1 = require("node:test");
|
|
13
|
+
const init_1 = require("../commands/init");
|
|
14
|
+
function withFetch(impl, run) {
|
|
15
|
+
const original = global.fetch;
|
|
16
|
+
global.fetch = impl;
|
|
17
|
+
return run().finally(() => { global.fetch = original; });
|
|
18
|
+
}
|
|
19
|
+
(0, node_test_1.describe)("checkoutCoverageComplete", () => {
|
|
20
|
+
(0, node_test_1.it)("fires for a complete project regardless of which commit or source produced that completeness", async () => {
|
|
21
|
+
const result = await withFetch(async () => ({ ok: true, json: async () => ({ state: "complete", coverage: 1, lastCommit: "some-other-commit-entirely", source: "github" }) }), () => (0, init_1.checkoutCoverageComplete)("https://api.test", "tok", true));
|
|
22
|
+
strict_1.default.equal(result, true);
|
|
23
|
+
});
|
|
24
|
+
(0, node_test_1.it)("does not fire for an incomplete project", async () => {
|
|
25
|
+
const result = await withFetch(async () => ({ ok: true, json: async () => ({ state: "partial", coverage: 0.4, source: "github" }) }), () => (0, init_1.checkoutCoverageComplete)("https://api.test", "tok", true));
|
|
26
|
+
strict_1.default.equal(result, false);
|
|
27
|
+
});
|
|
28
|
+
(0, node_test_1.it)("does not fire when this checkout's repo wasn't already a registered repo of the project — even if the project reports complete", async () => {
|
|
29
|
+
let called = false;
|
|
30
|
+
const result = await withFetch(async () => { called = true; return { ok: true, json: async () => ({ state: "complete" }) }; }, () => (0, init_1.checkoutCoverageComplete)("https://api.test", "tok", false));
|
|
31
|
+
strict_1.default.equal(result, false);
|
|
32
|
+
strict_1.default.equal(called, false, "must not even ask the server when this checkout's repo isn't confirmed registered");
|
|
33
|
+
});
|
|
34
|
+
(0, node_test_1.it)("fails open to false on a server error or network failure", async () => {
|
|
35
|
+
const errored = await withFetch(async () => ({ ok: false, json: async () => ({}) }), () => (0, init_1.checkoutCoverageComplete)("https://api.test", "tok", true));
|
|
36
|
+
strict_1.default.equal(errored, false);
|
|
37
|
+
const offline = await withFetch(async () => { throw new Error("network down"); }, () => (0, init_1.checkoutCoverageComplete)("https://api.test", "tok", true));
|
|
38
|
+
strict_1.default.equal(offline, false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
(0, node_test_1.describe)("shouldSkipLocalScan", () => {
|
|
42
|
+
(0, node_test_1.it)("skips when coverage is complete and neither --force nor --dry-run is set", () => {
|
|
43
|
+
strict_1.default.equal((0, init_1.shouldSkipLocalScan)(undefined, undefined, true), true);
|
|
44
|
+
});
|
|
45
|
+
(0, node_test_1.it)("--force always runs the full flow, even on a complete project", () => {
|
|
46
|
+
strict_1.default.equal((0, init_1.shouldSkipLocalScan)(true, undefined, true), false);
|
|
47
|
+
});
|
|
48
|
+
(0, node_test_1.it)("--dry-run always runs the full flow (dry-run stays fully local, never short-circuited)", () => {
|
|
49
|
+
strict_1.default.equal((0, init_1.shouldSkipLocalScan)(undefined, "/tmp/payload.json", true), false);
|
|
50
|
+
});
|
|
51
|
+
(0, node_test_1.it)("never skips when coverage is not complete", () => {
|
|
52
|
+
strict_1.default.equal((0, init_1.shouldSkipLocalScan)(undefined, undefined, false), false);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** Validation fixtures only; no production or customer identifiers. */
|
|
7
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const node_child_process_1 = require("node:child_process");
|
|
12
|
+
const node_test_1 = require("node:test");
|
|
13
|
+
const install_hook_1 = require("../commands/install-hook");
|
|
14
|
+
function makeRepo() {
|
|
15
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-install-hook-"));
|
|
16
|
+
(0, node_child_process_1.execFileSync)("git", ["init", "-q", root]);
|
|
17
|
+
return root;
|
|
18
|
+
}
|
|
19
|
+
(0, node_test_1.describe)("installHookCommand", () => {
|
|
20
|
+
(0, node_test_1.it)("installs once, reports installed:true, and never installs a second hook block on a repeat call", async () => {
|
|
21
|
+
const root = makeRepo();
|
|
22
|
+
const first = await (0, install_hook_1.installHookCommand)({ repo: root });
|
|
23
|
+
strict_1.default.equal(first, true);
|
|
24
|
+
const hookPath = node_path_1.default.join(root, ".git", "hooks", "post-commit");
|
|
25
|
+
const afterFirst = node_fs_1.default.readFileSync(hookPath, "utf-8");
|
|
26
|
+
strict_1.default.equal((afterFirst.match(/# <kodingo>/g) ?? []).length, 1);
|
|
27
|
+
const second = await (0, install_hook_1.installHookCommand)({ repo: root });
|
|
28
|
+
strict_1.default.equal(second, false, "a repeat install must report installed:false, so the caller prints exactly one accurate line");
|
|
29
|
+
const afterSecond = node_fs_1.default.readFileSync(hookPath, "utf-8");
|
|
30
|
+
strict_1.default.equal(afterSecond, afterFirst, "the hook file must be byte-identical — no duplicate kodingo block appended");
|
|
31
|
+
strict_1.default.equal((afterSecond.match(/# <kodingo>/g) ?? []).length, 1);
|
|
32
|
+
});
|
|
33
|
+
(0, node_test_1.it)("the deep-scan line is backgrounded end-to-end, under a portable (non-GNU-timeout-dependent) watchdog, with its output silenced", async () => {
|
|
34
|
+
const root = makeRepo();
|
|
35
|
+
await (0, install_hook_1.installHookCommand)({ repo: root });
|
|
36
|
+
const hook = node_fs_1.default.readFileSync(node_path_1.default.join(root, ".git", "hooks", "post-commit"), "utf-8");
|
|
37
|
+
// The whole deep-scan block is one backgrounded subshell...
|
|
38
|
+
strict_1.default.match(hook, /\(\n\s*".*" deep-scan .* --changed --yes --no-update >\/dev\/null 2>&1 &\n/);
|
|
39
|
+
strict_1.default.match(hook, /\) &\s*\n# <\/kodingo>/);
|
|
40
|
+
// ...with a sleep+kill watchdog that doesn't depend on the GNU `timeout`
|
|
41
|
+
// binary being installed (unlike a plain `command -v timeout` check).
|
|
42
|
+
strict_1.default.match(hook, /sleep 120.*kill -9/);
|
|
43
|
+
strict_1.default.doesNotMatch(hook, /command -v timeout/);
|
|
44
|
+
// scan-git and sync-dependencies are also silenced, so an uncaught
|
|
45
|
+
// exception in either never prints a stack trace to the user's terminal.
|
|
46
|
+
strict_1.default.match(hook, /scan-git --repo "\$\(git rev-parse --show-toplevel\)" >\/dev\/null 2>&1 &/);
|
|
47
|
+
strict_1.default.match(hook, /sync-dependencies --repo "\$\(git rev-parse --show-toplevel\)" >\/dev\/null 2>&1 &/);
|
|
48
|
+
});
|
|
49
|
+
(0, node_test_1.it)("never prompts: deep-scan always runs with --yes", async () => {
|
|
50
|
+
const root = makeRepo();
|
|
51
|
+
await (0, install_hook_1.installHookCommand)({ repo: root });
|
|
52
|
+
const hook = node_fs_1.default.readFileSync(node_path_1.default.join(root, ".git", "hooks", "post-commit"), "utf-8");
|
|
53
|
+
strict_1.default.match(hook, /--yes/);
|
|
54
|
+
});
|
|
55
|
+
(0, node_test_1.it)("is chmod +x so git will actually execute it, and is a post-commit hook (never blocks or fails the commit by construction)", async () => {
|
|
56
|
+
const root = makeRepo();
|
|
57
|
+
await (0, install_hook_1.installHookCommand)({ repo: root });
|
|
58
|
+
const hookPath = node_path_1.default.join(root, ".git", "hooks", "post-commit");
|
|
59
|
+
const mode = node_fs_1.default.statSync(hookPath).mode & 0o777;
|
|
60
|
+
strict_1.default.equal(mode, 0o755);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/** Validation fixtures only; no production or customer identifiers. */
|
|
7
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
+
const node_test_1 = require("node:test");
|
|
9
|
+
const deep_scan_1 = require("../commands/deep-scan");
|
|
10
|
+
function withCapturedLog(run) {
|
|
11
|
+
const logs = [];
|
|
12
|
+
const original = console.log;
|
|
13
|
+
console.log = (...args) => { logs.push(args.join(" ")); };
|
|
14
|
+
try {
|
|
15
|
+
run();
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
console.log = original;
|
|
19
|
+
}
|
|
20
|
+
return logs;
|
|
21
|
+
}
|
|
22
|
+
(0, node_test_1.describe)("printFinalOutcome", () => {
|
|
23
|
+
(0, node_test_1.it)("prints an applied summary with entities/edges/files, and never sets a non-zero exit code", () => {
|
|
24
|
+
const originalExitCode = process.exitCode;
|
|
25
|
+
process.exitCode = undefined;
|
|
26
|
+
try {
|
|
27
|
+
const logs = withCapturedLog(() => (0, deep_scan_1.printFinalOutcome)({ applied: true, entity_count: 5, edge_count: 2, file_count: 3 }, true));
|
|
28
|
+
strict_1.default.ok(logs.some((line) => /Deep scan applied: 5 entities, 2 edges, 3 files/.test(line)));
|
|
29
|
+
strict_1.default.notEqual(process.exitCode, 1);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
process.exitCode = originalExitCode;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
(0, node_test_1.it)("never prints 'accepted' and, under --yes, exits non-zero when held", () => {
|
|
36
|
+
const originalExitCode = process.exitCode;
|
|
37
|
+
process.exitCode = undefined;
|
|
38
|
+
try {
|
|
39
|
+
const logs = withCapturedLog(() => (0, deep_scan_1.printFinalOutcome)({ applied: false, apply_reason: "dirty_checkout" }, true));
|
|
40
|
+
strict_1.default.ok(logs.some((line) => /^Deep scan held:/.test(line)));
|
|
41
|
+
strict_1.default.ok(!logs.some((line) => /accepted/i.test(line)));
|
|
42
|
+
strict_1.default.equal(process.exitCode, 1);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
process.exitCode = originalExitCode;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
(0, node_test_1.it)("does not force a non-zero exit when held outside --yes", () => {
|
|
49
|
+
const originalExitCode = process.exitCode;
|
|
50
|
+
process.exitCode = undefined;
|
|
51
|
+
try {
|
|
52
|
+
withCapturedLog(() => (0, deep_scan_1.printFinalOutcome)({ applied: false, apply_reason: "dirty_checkout" }, false));
|
|
53
|
+
strict_1.default.notEqual(process.exitCode, 1);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
process.exitCode = originalExitCode;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
(0, node_test_1.describe)("pollRun", () => {
|
|
61
|
+
(0, node_test_1.it)("returns as soon as the run reaches a terminal state, backing off between polls", async () => {
|
|
62
|
+
const original = global.fetch;
|
|
63
|
+
let calls = 0;
|
|
64
|
+
global.fetch = async () => {
|
|
65
|
+
calls += 1;
|
|
66
|
+
const state = calls < 2 ? "running" : "completed";
|
|
67
|
+
return { ok: true, status: 200, json: async () => ({ state }) };
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
const run = await (0, deep_scan_1.pollRun)("https://api.test", "tok", "run-1", 5000);
|
|
71
|
+
strict_1.default.equal(run.state, "completed");
|
|
72
|
+
strict_1.default.equal(calls, 2);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
global.fetch = original;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
(0, node_test_1.it)("gives up and returns the last known state once the timeout elapses", async () => {
|
|
79
|
+
const original = global.fetch;
|
|
80
|
+
global.fetch = async () => ({ ok: true, status: 200, json: async () => ({ state: "running" }) });
|
|
81
|
+
try {
|
|
82
|
+
const run = await (0, deep_scan_1.pollRun)("https://api.test", "tok", "run-1", 1);
|
|
83
|
+
strict_1.default.equal(run.state, "running");
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
global.fetch = original;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -118,3 +118,35 @@ function makeTempDir() {
|
|
|
118
118
|
strict_1.default.equal(result, "fot");
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
|
+
(0, node_test_1.describe)("resolveRepoRegistration — the gate the complete-coverage shortcut needs", () => {
|
|
122
|
+
let dir;
|
|
123
|
+
const originalFetch = globalThis.fetch;
|
|
124
|
+
(0, node_test_1.beforeEach)(() => {
|
|
125
|
+
dir = makeTempDir();
|
|
126
|
+
(0, node_child_process_1.execSync)("git init -q", { cwd: dir });
|
|
127
|
+
(0, node_child_process_1.execSync)("git remote add origin https://github.com/abokidev/fot.git", { cwd: dir });
|
|
128
|
+
});
|
|
129
|
+
(0, node_test_1.afterEach)(() => {
|
|
130
|
+
node_fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
131
|
+
globalThis.fetch = originalFetch;
|
|
132
|
+
});
|
|
133
|
+
for (const matched of ["single-registered", "multi-matched"]) {
|
|
134
|
+
(0, node_test_1.it)(`alreadyRegistered:true when the server reports "${matched}" — a repo that pre-existed this call`, async () => {
|
|
135
|
+
globalThis.fetch = (async () => new Response(JSON.stringify({ repoName: "fot", registered: false, matched }), { status: 200 }));
|
|
136
|
+
const result = await (0, repo_identity_1.resolveRepoRegistration)({ repoRoot: dir, apiUrl: "https://example.invalid", token: "t" });
|
|
137
|
+
strict_1.default.deepEqual(result, { repoName: "fot", alreadyRegistered: true });
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
for (const matched of ["first-registration", "multi-new"]) {
|
|
141
|
+
(0, node_test_1.it)(`alreadyRegistered:false when the server reports "${matched}" — this call just registered it for the first time`, async () => {
|
|
142
|
+
globalThis.fetch = (async () => new Response(JSON.stringify({ repoName: "fot", registered: true, matched }), { status: 200 }));
|
|
143
|
+
const result = await (0, repo_identity_1.resolveRepoRegistration)({ repoRoot: dir, apiUrl: "https://example.invalid", token: "t" });
|
|
144
|
+
strict_1.default.deepEqual(result, { repoName: "fot", alreadyRegistered: false });
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
(0, node_test_1.it)("alreadyRegistered:false when the server is unreachable — never trust a merely-local fallback as a registered match", async () => {
|
|
148
|
+
globalThis.fetch = (async () => { throw new Error("network down"); });
|
|
149
|
+
const result = await (0, repo_identity_1.resolveRepoRegistration)({ repoRoot: dir, apiUrl: "https://example.invalid", token: "t" });
|
|
150
|
+
strict_1.default.deepEqual(result, { repoName: "fot", alreadyRegistered: false });
|
|
151
|
+
});
|
|
152
|
+
});
|