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,353 @@
|
|
|
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
|
+
* The "coverage already complete, skip the local scan" path must still
|
|
8
|
+
* settle the tracked branch — otherwise a project with complete coverage
|
|
9
|
+
* but no recorded tracked branch holds every future commit (including the
|
|
10
|
+
* commit hook's) forever, with no visible error. Covers that settlement,
|
|
11
|
+
* its truthful closing message, and reconciling a held scan once recording
|
|
12
|
+
* fixes it.
|
|
13
|
+
*
|
|
14
|
+
* Live bug this fixes: reconciliation read `status.lastScan` — the
|
|
15
|
+
* project's single most recent scan of ANY source — instead of
|
|
16
|
+
* `status.lastCliScan`. A project read through GitHub has an hourly
|
|
17
|
+
* github_light_backup row (source:'github', applied:true) as its most
|
|
18
|
+
* recent scan; reading `lastScan` meant the `applied` short-circuit always
|
|
19
|
+
* fired on that backup row, so a genuinely held CLI scan sitting in
|
|
20
|
+
* `lastCliScan` was never even looked at, let alone re-applied.
|
|
21
|
+
*/
|
|
22
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
23
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
24
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
25
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
26
|
+
const node_child_process_1 = require("node:child_process");
|
|
27
|
+
const node_test_1 = require("node:test");
|
|
28
|
+
const deep_scan_1 = require("../commands/deep-scan");
|
|
29
|
+
function fakeFetch(responses) {
|
|
30
|
+
const calls = [];
|
|
31
|
+
const fn = async (url, init) => {
|
|
32
|
+
calls.push({ url, init });
|
|
33
|
+
const next = responses.shift();
|
|
34
|
+
if (!next)
|
|
35
|
+
throw new Error(`settleAlreadyCompleteProject test: no mock response left for ${url}`);
|
|
36
|
+
return { ok: (next.status ?? 200) < 300, status: next.status ?? 200, json: async () => next.body };
|
|
37
|
+
};
|
|
38
|
+
return { fn, calls };
|
|
39
|
+
}
|
|
40
|
+
function withFetch(responses, run) {
|
|
41
|
+
const original = global.fetch;
|
|
42
|
+
const { fn, calls } = fakeFetch(responses);
|
|
43
|
+
global.fetch = fn;
|
|
44
|
+
return run(calls).finally(() => { global.fetch = original; });
|
|
45
|
+
}
|
|
46
|
+
function withConsoleLog(run) {
|
|
47
|
+
const logs = [];
|
|
48
|
+
const original = console.log;
|
|
49
|
+
console.log = (...args) => { logs.push(args.join(" ")); };
|
|
50
|
+
return run(logs).finally(() => { console.log = original; });
|
|
51
|
+
}
|
|
52
|
+
function makeRepo(branch = "main") {
|
|
53
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "kodingo-complete-settle-"));
|
|
54
|
+
(0, node_child_process_1.execFileSync)("git", ["init", "-q", "-b", branch, root]);
|
|
55
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.email", "test@example.invalid"]);
|
|
56
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "config", "user.name", "Validation Test"]);
|
|
57
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "remote", "add", "origin", "git@github.com:org/repo.git"]);
|
|
58
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, "a.ts"), "export const a = 1;\n");
|
|
59
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "add", "."]);
|
|
60
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "commit", "-qm", "fixture"]);
|
|
61
|
+
return root;
|
|
62
|
+
}
|
|
63
|
+
const baseOpts = (root, branch) => ({
|
|
64
|
+
apiUrl: "https://api.test", token: "tok", root,
|
|
65
|
+
branch, detachedHead: false, repository: "org/repo", repositoryName: "repo",
|
|
66
|
+
});
|
|
67
|
+
const githubBackupScan = { id: "scan-github", commitSha: "g".repeat(40), applied: true, reason: "github_light_backup", entityCount: 40, edgeCount: 10, fileCount: 0 };
|
|
68
|
+
(0, node_test_1.describe)("settleAlreadyCompleteProject — the real live shape (tracked branch recorded in an EARLIER run)", () => {
|
|
69
|
+
(0, node_test_1.it)("reproduction: an already-recorded tracked branch (outcome:'match') must still trigger reconciliation of a held CLI scan", async () => {
|
|
70
|
+
const root = makeRepo("main");
|
|
71
|
+
await withConsoleLog((logs) => withFetch([
|
|
72
|
+
{ body: { outcome: "match", trackedBranch: "main" } }, // settle check — already recorded, matches checkout
|
|
73
|
+
{
|
|
74
|
+
body: {
|
|
75
|
+
state: "complete",
|
|
76
|
+
lastScan: { id: "scan-github", commitSha: "g".repeat(40), applied: true, reason: "github_light_backup" },
|
|
77
|
+
lastCliScan: { id: "scan-cli-held", commitSha: "deadbeef".repeat(5), applied: false, reason: "branch_mismatch:main:unregistered", entityCount: 0, edgeCount: 0, fileCount: 0 },
|
|
78
|
+
lastGithubScan: { commitSha: "g".repeat(40), completedAt: "2026-11-05T00:00:00.000Z" },
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{ body: { scanId: "scan-cli-held", applied: true, reason: "clean_tracked_branch", entityCount: 2, edgeCount: 1, fileCount: 2 } },
|
|
82
|
+
], async (calls) => {
|
|
83
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
84
|
+
strict_1.default.equal(calls.length, 3, `expected the settle check, the reconcile status read, and the reapply call — got: ${JSON.stringify(calls.map((c) => c.url))}`);
|
|
85
|
+
strict_1.default.match(calls[2].url, /\/deep-scan\/scans\/scan-cli-held\/reapply$/);
|
|
86
|
+
strict_1.default.ok(logs.some((l) => /Deep scan applied: 2 entities, 1 edges, 2 files/.test(l)), `expected an applied summary line, got: ${JSON.stringify(logs)}`);
|
|
87
|
+
}));
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
(0, node_test_1.describe)("settleAlreadyCompleteProject", () => {
|
|
91
|
+
(0, node_test_1.it)("--yes on the remote's default branch: records the tracked branch and prints the confident closing message", async () => {
|
|
92
|
+
const root = makeRepo("main");
|
|
93
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
94
|
+
await withConsoleLog((logs) => withFetch([
|
|
95
|
+
{ body: { outcome: "none", trackedBranch: null } }, // check
|
|
96
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } }, // record
|
|
97
|
+
{ body: { lastScan: null, lastCliScan: null } }, // reconcile's status read — nothing held
|
|
98
|
+
], async (calls) => {
|
|
99
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
100
|
+
strict_1.default.equal(calls.length, 3);
|
|
101
|
+
strict_1.default.ok(logs.some((l) => /Tracked branch for org\/repo set to "main"/.test(l)));
|
|
102
|
+
strict_1.default.ok(logs.some((l) => l === "Kortex already has a complete read of this project. Your commits will keep it up to date."));
|
|
103
|
+
}));
|
|
104
|
+
});
|
|
105
|
+
(0, node_test_1.it)("the live bug's exact shape: lastScan is an applied GitHub backup, the held CLI scan is in lastCliScan — it IS re-applied", async () => {
|
|
106
|
+
const root = makeRepo("main");
|
|
107
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
108
|
+
await withConsoleLog((logs) => withFetch([
|
|
109
|
+
{ body: { outcome: "none", trackedBranch: null } },
|
|
110
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } },
|
|
111
|
+
{
|
|
112
|
+
body: {
|
|
113
|
+
lastScan: githubBackupScan, // most recent overall: the GitHub backup — applied:true
|
|
114
|
+
lastCliScan: { id: "scan-cli-held", commitSha: "deadbeef".repeat(5), applied: false, reason: "branch_mismatch:main:unregistered" },
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{ body: { scanId: "scan-cli-held", applied: true, reason: "clean_tracked_branch", entityCount: 9, edgeCount: 2, fileCount: 3 } },
|
|
118
|
+
], async (calls) => {
|
|
119
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
120
|
+
strict_1.default.equal(calls.length, 4);
|
|
121
|
+
strict_1.default.match(calls[3].url, /\/deep-scan\/scans\/scan-cli-held\/reapply$/);
|
|
122
|
+
strict_1.default.ok(logs.some((l) => /Deep scan applied: 9 entities, 2 edges, 3 files/.test(l)));
|
|
123
|
+
strict_1.default.ok(logs.some((l) => l === "Kortex already has a complete read of this project. Your commits will keep it up to date."));
|
|
124
|
+
}));
|
|
125
|
+
});
|
|
126
|
+
(0, node_test_1.it)("--yes on a feature branch (not the default): refuses without recording — the whole call rejects", async () => {
|
|
127
|
+
const root = makeRepo("feature/x");
|
|
128
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
129
|
+
await withFetch([{ body: { outcome: "none", trackedBranch: null } }], async () => {
|
|
130
|
+
await strict_1.default.rejects(() => (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "feature/x"), yes: true }), /does not match the remote's default branch/);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
(0, node_test_1.it)("a different tracked branch is never overwritten; the closing message names it and is never the confident one; held-scan state is still checked (the tracked branch, 'main', exists — just not for this checkout's branch)", async () => {
|
|
134
|
+
const root = makeRepo("feature/x");
|
|
135
|
+
await withConsoleLog((logs) => withFetch([
|
|
136
|
+
{ body: { outcome: "mismatch", trackedBranch: "main" } },
|
|
137
|
+
{ body: { lastCliScan: null } }, // reconcile still runs — a tracked branch ("main") exists
|
|
138
|
+
], async (calls) => {
|
|
139
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "feature/x"), yes: true });
|
|
140
|
+
strict_1.default.equal(calls.length, 2, "mismatch never attempts to record, but a tracked branch exists so held-scan state is still checked");
|
|
141
|
+
strict_1.default.ok(logs.some((l) => /This project tracks "main"/.test(l) && /commits on "feature\/x" will not update Kortex/.test(l)));
|
|
142
|
+
strict_1.default.ok(logs.some((l) => l === "No CLI scan is currently held."), "every branch must report held-scan state, never silently");
|
|
143
|
+
strict_1.default.equal(logs.some((l) => l.includes("Your commits will keep it up to date")), false);
|
|
144
|
+
}));
|
|
145
|
+
});
|
|
146
|
+
(0, node_test_1.it)("the closing message is the confident one when the branch already matches (no recording needed); held-scan state is still checked", async () => {
|
|
147
|
+
const root = makeRepo("main");
|
|
148
|
+
await withConsoleLog((logs) => withFetch([
|
|
149
|
+
{ body: { outcome: "match", trackedBranch: "main" } },
|
|
150
|
+
{ body: { lastCliScan: null } }, // reconcile still runs — "match" means a tracked branch exists
|
|
151
|
+
], async (calls) => {
|
|
152
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
153
|
+
strict_1.default.equal(calls.length, 2, "a match never records, but a tracked branch already exists so held-scan state is still checked");
|
|
154
|
+
strict_1.default.ok(logs.some((l) => l === "No CLI scan is currently held."));
|
|
155
|
+
strict_1.default.ok(logs.some((l) => l === "Kortex already has a complete read of this project. Your commits will keep it up to date."));
|
|
156
|
+
}));
|
|
157
|
+
});
|
|
158
|
+
(0, node_test_1.it)("a held scan is re-applied after recording fixes its reason — even at an older commit than HEAD", async () => {
|
|
159
|
+
const root = makeRepo("main");
|
|
160
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
161
|
+
await withConsoleLog((logs) => withFetch([
|
|
162
|
+
{ body: { outcome: "none", trackedBranch: null } },
|
|
163
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } },
|
|
164
|
+
{ body: { lastCliScan: { id: "scan-1", commitSha: "deadbeef".repeat(5), applied: false, reason: "branch_mismatch:main:unregistered" } } },
|
|
165
|
+
{ body: { scanId: "scan-1", applied: true, reason: "clean_tracked_branch", entityCount: 9, edgeCount: 2, fileCount: 3 } },
|
|
166
|
+
], async (calls) => {
|
|
167
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
168
|
+
strict_1.default.equal(calls.length, 4);
|
|
169
|
+
strict_1.default.match(calls[3].url, /\/deep-scan\/scans\/scan-1\/reapply$/);
|
|
170
|
+
strict_1.default.ok(logs.some((l) => /Deep scan applied: 9 entities, 2 edges, 3 files/.test(l)));
|
|
171
|
+
}));
|
|
172
|
+
});
|
|
173
|
+
(0, node_test_1.it)("does not reapply a held scan whose reason recording didn't fix (e.g. a stale dirty_checkout) — and the confident line still prints, since that old, unrelated hold isn't something this flow is responsible for", async () => {
|
|
174
|
+
const root = makeRepo("main");
|
|
175
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
176
|
+
await withConsoleLog((logs) => withFetch([
|
|
177
|
+
{ body: { outcome: "none", trackedBranch: null } },
|
|
178
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } },
|
|
179
|
+
{ body: { lastCliScan: { id: "scan-1", commitSha: "x".repeat(40), applied: false, reason: "dirty_checkout" } } },
|
|
180
|
+
], async (calls) => {
|
|
181
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
182
|
+
strict_1.default.equal(calls.length, 3, "must not call reapply — dirty_checkout isn't fixed by a tracked-branch recording");
|
|
183
|
+
strict_1.default.ok(logs.some((l) => l === "Kortex already has a complete read of this project. Your commits will keep it up to date."));
|
|
184
|
+
}));
|
|
185
|
+
});
|
|
186
|
+
(0, node_test_1.it)("session expired: reports the clear next step and withholds the confident closing line", async () => {
|
|
187
|
+
const root = makeRepo("main");
|
|
188
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
189
|
+
// --yes + an unresolved outcome sets process.exitCode=1 (so CI notices) —
|
|
190
|
+
// save/restore it, matching pollAndOutcome.test.ts's own established
|
|
191
|
+
// pattern, so this test's own exit status isn't poisoned by it.
|
|
192
|
+
const originalExitCode = process.exitCode;
|
|
193
|
+
process.exitCode = undefined;
|
|
194
|
+
try {
|
|
195
|
+
await withConsoleLog((logs) => withFetch([
|
|
196
|
+
{ body: { outcome: "none", trackedBranch: null } },
|
|
197
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } },
|
|
198
|
+
{ body: { lastCliScan: { id: "scan-1", commitSha: "deadbeef".repeat(5), applied: false, reason: "branch_mismatch:main:unregistered" } } },
|
|
199
|
+
{ body: { scanId: "scan-1", applied: false, reason: "branch_mismatch:main:unregistered", sessionExpired: true } },
|
|
200
|
+
], async (calls) => {
|
|
201
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
202
|
+
strict_1.default.equal(calls.length, 4);
|
|
203
|
+
strict_1.default.ok(logs.some((l) => l === "The held scan can no longer be applied (its upload session expired). Run `kodingo init --force` to scan again."));
|
|
204
|
+
strict_1.default.equal(logs.some((l) => l.includes("Your commits will keep it up to date")), false);
|
|
205
|
+
strict_1.default.equal(process.exitCode, 1);
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
process.exitCode = originalExitCode;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
(0, node_test_1.it)("a server error re-applying is reported in plain words, never thrown, and withholds the confident closing line", async () => {
|
|
213
|
+
const root = makeRepo("main");
|
|
214
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
215
|
+
const originalExitCode = process.exitCode;
|
|
216
|
+
process.exitCode = undefined;
|
|
217
|
+
try {
|
|
218
|
+
await withConsoleLog((logs) => withFetch([
|
|
219
|
+
{ body: { outcome: "none", trackedBranch: null } },
|
|
220
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } },
|
|
221
|
+
{ body: { lastCliScan: { id: "scan-1", commitSha: "deadbeef".repeat(5), applied: false, reason: "branch_mismatch:main:unregistered" } } },
|
|
222
|
+
{ status: 500, body: { error: "internal error" } },
|
|
223
|
+
], async (calls) => {
|
|
224
|
+
await strict_1.default.doesNotReject(() => (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true }));
|
|
225
|
+
strict_1.default.equal(calls.length, 4);
|
|
226
|
+
strict_1.default.ok(logs.some((l) => /Could not re-apply the held scan/.test(l)));
|
|
227
|
+
strict_1.default.equal(logs.some((l) => l.includes("Your commits will keep it up to date")), false);
|
|
228
|
+
strict_1.default.equal(process.exitCode, 1);
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
process.exitCode = originalExitCode;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
(0, node_test_1.it)("a stale full-tree refusal from the server is reported in plain words, and withholds the confident closing line", async () => {
|
|
236
|
+
const root = makeRepo("main");
|
|
237
|
+
(0, node_child_process_1.execFileSync)("git", ["-C", root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"]);
|
|
238
|
+
const originalExitCode = process.exitCode;
|
|
239
|
+
process.exitCode = undefined;
|
|
240
|
+
try {
|
|
241
|
+
await withConsoleLog((logs) => withFetch([
|
|
242
|
+
{ body: { outcome: "none", trackedBranch: null } },
|
|
243
|
+
{ body: { outcome: "recorded", trackedBranch: "main" } },
|
|
244
|
+
{ body: { lastCliScan: { id: "scan-1", commitSha: "deadbeef".repeat(5), applied: false, reason: "branch_mismatch:main:unregistered" } } },
|
|
245
|
+
{ body: { scanId: "scan-1", applied: false, reason: "stale_full_tree" } },
|
|
246
|
+
], async (calls) => {
|
|
247
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
248
|
+
strict_1.default.equal(calls.length, 4);
|
|
249
|
+
strict_1.default.ok(logs.some((l) => /full-repository scan/i.test(l) && /no longer the tracked branch's current head/i.test(l)));
|
|
250
|
+
strict_1.default.equal(logs.some((l) => l.includes("Your commits will keep it up to date")), false);
|
|
251
|
+
strict_1.default.equal(process.exitCode, 1);
|
|
252
|
+
}));
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
process.exitCode = originalExitCode;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
(0, node_test_1.it)("detached HEAD: skips settlement entirely, never claims commits will keep Kortex up to date", async () => {
|
|
259
|
+
const root = makeRepo("main");
|
|
260
|
+
await withConsoleLog((logs) => withFetch([], async (calls) => {
|
|
261
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), detachedHead: true, branch: null, yes: true });
|
|
262
|
+
strict_1.default.equal(calls.length, 0, "no network call at all for a detached checkout");
|
|
263
|
+
strict_1.default.equal(logs.some((l) => l.includes("Your commits will keep it up to date")), false);
|
|
264
|
+
strict_1.default.ok(logs.some((l) => /detached HEAD/i.test(l)));
|
|
265
|
+
strict_1.default.ok(logs.some((l) => /held scan state/i.test(l)), "must still say something about held-scan state, even here");
|
|
266
|
+
}));
|
|
267
|
+
});
|
|
268
|
+
(0, node_test_1.it)("no tracked branch exists at all (interactive decline, non-TTY auto-declines): held-scan state is NOT checked, and says so plainly", async () => {
|
|
269
|
+
const root = makeRepo("main");
|
|
270
|
+
await withConsoleLog((logs) => withFetch([{ body: { outcome: "none", trackedBranch: null } }], async (calls) => {
|
|
271
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: false });
|
|
272
|
+
strict_1.default.equal(calls.length, 1, "no tracked branch exists, so reconciliation never even attempts a status read");
|
|
273
|
+
strict_1.default.ok(logs.some((l) => l === "No tracked branch exists yet, so no held scan was checked."));
|
|
274
|
+
strict_1.default.equal(logs.some((l) => l.includes("Your commits will keep it up to date")), false);
|
|
275
|
+
}));
|
|
276
|
+
});
|
|
277
|
+
(0, node_test_1.it)("a held scan exists but isn't fixed by the tracked branch: reports the reason and next step plainly, without attempting reapply", async () => {
|
|
278
|
+
const root = makeRepo("main");
|
|
279
|
+
await withConsoleLog((logs) => withFetch([
|
|
280
|
+
{ body: { outcome: "match", trackedBranch: "main" } },
|
|
281
|
+
{ body: { lastCliScan: { id: "scan-1", commitSha: "x".repeat(40), applied: false, reason: "dirty_checkout" } } },
|
|
282
|
+
], async (calls) => {
|
|
283
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
284
|
+
strict_1.default.equal(calls.length, 2, "must not call reapply — checked client-side that dirty_checkout isn't fixable");
|
|
285
|
+
strict_1.default.ok(logs.some((l) => l.startsWith("A held scan exists, but the tracked branch doesn't fix it:") && /uncommitted changes/.test(l)));
|
|
286
|
+
}));
|
|
287
|
+
});
|
|
288
|
+
(0, node_test_1.it)("--verbose prints the decision inputs: tracked branch, held scan id/commit/reason, and the fixability decision", async () => {
|
|
289
|
+
const root = makeRepo("main");
|
|
290
|
+
await withConsoleLog((logs) => withFetch([
|
|
291
|
+
{ body: { outcome: "match", trackedBranch: "main" } },
|
|
292
|
+
{ body: { lastCliScan: { id: "scan-cli-held", commitSha: "deadbeef".repeat(5), applied: false, reason: "branch_mismatch:main:unregistered", fixableByTrackedBranch: true } } },
|
|
293
|
+
{ body: { scanId: "scan-cli-held", applied: true, reason: "clean_tracked_branch", entityCount: 1, edgeCount: 0, fileCount: 1 } },
|
|
294
|
+
], async () => {
|
|
295
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true, verbose: true });
|
|
296
|
+
const debugLine = logs.find((l) => l.startsWith("[debug]"));
|
|
297
|
+
strict_1.default.ok(debugLine, `expected a [debug] line, got: ${JSON.stringify(logs)}`);
|
|
298
|
+
strict_1.default.match(debugLine, /tracked branch=main/);
|
|
299
|
+
strict_1.default.match(debugLine, /id=scan-cli-held/);
|
|
300
|
+
strict_1.default.match(debugLine, /commit=deadbeef/);
|
|
301
|
+
strict_1.default.match(debugLine, /reason=branch_mismatch:main:unregistered/);
|
|
302
|
+
strict_1.default.match(debugLine, /fixable=true/);
|
|
303
|
+
}));
|
|
304
|
+
});
|
|
305
|
+
(0, node_test_1.it)("--verbose stays silent on the debug line (but not the plain-words line) when not passed", async () => {
|
|
306
|
+
const root = makeRepo("main");
|
|
307
|
+
await withConsoleLog((logs) => withFetch([
|
|
308
|
+
{ body: { outcome: "match", trackedBranch: "main" } },
|
|
309
|
+
{ body: { lastCliScan: null } },
|
|
310
|
+
], async () => {
|
|
311
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: true });
|
|
312
|
+
strict_1.default.equal(logs.some((l) => l.startsWith("[debug]")), false);
|
|
313
|
+
strict_1.default.ok(logs.some((l) => l === "No CLI scan is currently held."));
|
|
314
|
+
}));
|
|
315
|
+
});
|
|
316
|
+
(0, node_test_1.it)("no combination of these inputs produces zero output about the held scan", async () => {
|
|
317
|
+
const scenarios = [
|
|
318
|
+
{ name: "match, nothing held", responses: [{ body: { outcome: "match", trackedBranch: "main" } }, { body: { lastCliScan: null } }] },
|
|
319
|
+
{ name: "match, held and fixable", responses: [
|
|
320
|
+
{ body: { outcome: "match", trackedBranch: "main" } },
|
|
321
|
+
{ body: { lastCliScan: { id: "s1", commitSha: "a".repeat(40), applied: false, reason: "branch_mismatch:main:unregistered" } } },
|
|
322
|
+
{ body: { scanId: "s1", applied: true, reason: "clean_tracked_branch", entityCount: 1, edgeCount: 0, fileCount: 1 } },
|
|
323
|
+
] },
|
|
324
|
+
{ name: "match, held but not fixable", responses: [
|
|
325
|
+
{ body: { outcome: "match", trackedBranch: "main" } },
|
|
326
|
+
{ body: { lastCliScan: { id: "s1", commitSha: "a".repeat(40), applied: false, reason: "dirty_checkout" } } },
|
|
327
|
+
] },
|
|
328
|
+
{ name: "match, held but session expired", responses: [
|
|
329
|
+
{ body: { outcome: "match", trackedBranch: "main" } },
|
|
330
|
+
{ body: { lastCliScan: { id: "s1", commitSha: "a".repeat(40), applied: false, reason: "branch_mismatch:main:unregistered" } } },
|
|
331
|
+
{ body: { scanId: "s1", applied: false, reason: "branch_mismatch:main:unregistered", sessionExpired: true } },
|
|
332
|
+
] },
|
|
333
|
+
{ name: "mismatch", responses: [{ body: { outcome: "mismatch", trackedBranch: "main" } }, { body: { lastCliScan: null } }] },
|
|
334
|
+
{ name: "none, declined", responses: [{ body: { outcome: "none", trackedBranch: null } }] },
|
|
335
|
+
{ name: "status check errors", responses: [{ body: { outcome: "match", trackedBranch: "main" } }, { status: 500, body: { error: "boom" } }] },
|
|
336
|
+
];
|
|
337
|
+
for (const scenario of scenarios) {
|
|
338
|
+
const root = makeRepo("main");
|
|
339
|
+
const originalExitCode = process.exitCode;
|
|
340
|
+
process.exitCode = undefined;
|
|
341
|
+
try {
|
|
342
|
+
await withConsoleLog((logs) => withFetch(scenario.responses, async () => {
|
|
343
|
+
await (0, deep_scan_1.settleAlreadyCompleteProject)({ ...baseOpts(root, "main"), yes: scenario.name !== "none, declined" });
|
|
344
|
+
const heldScanLines = logs.filter((l) => /held scan|CLI scan is currently held|tracked branch exists|re-applied|Deep scan applied|Deep scan held|Could not/i.test(l));
|
|
345
|
+
strict_1.default.ok(heldScanLines.length > 0, `scenario "${scenario.name}" produced no output about the held scan — got: ${JSON.stringify(logs)}`);
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
process.exitCode = originalExitCode;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
});
|
package/dist/cli.js
CHANGED
|
@@ -261,7 +261,8 @@ program
|
|
|
261
261
|
const payload = {};
|
|
262
262
|
if (options.repo)
|
|
263
263
|
payload.repo = String(options.repo);
|
|
264
|
-
await (0, install_hook_1.installHookCommand)(payload);
|
|
264
|
+
const installed = await (0, install_hook_1.installHookCommand)(payload);
|
|
265
|
+
console.log(installed ? "Kodingo hook installed." : "Hook already installed.");
|
|
265
266
|
});
|
|
266
267
|
// ── scan-claude ──────────────────────────────────────────────────────────────
|
|
267
268
|
program
|