Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { writeFile, unlink, mkdir, rmdir, rm } from "node:fs/promises";
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { runDoctor } from "./doctor.js";
import { runDoctor, triageGateStatus } from "./doctor.js";
import { loadOrCreateIdentity, identityId } from "./identity.js";
import { resolveKeyStore } from "./keystore/index.js";
import {
Expand Down Expand Up @@ -230,6 +230,21 @@ describe("runDoctor", () => {
}
});

it("triage pre-commit gates: check is always present (skip when not wired)", async () => {
const tmpDir = join(tmpdir(), `kit-doctor-test-${process.pid}-triage-gates`);
await mkdir(tmpDir, { recursive: true });
try {
const result = await runDoctor({}, tmpDir);
const g = result.checks.find((c) => c.name === "triage pre-commit gates");
assert.ok(g, "triage pre-commit gates check should always be present");
// tmpDir is not a git repo → skip; a wired repo would be pass — both honest.
assert.ok(["skip", "pass", "warn"].includes(g.status), `unexpected status: ${g.status}`);
assert.ok(g.detail.length > 0);
} finally {
await rm(tmpDir, { recursive: true });
}
});

it("surfaces the identity keystore posture (Pelare 1 — never silent)", async () => {
const tmpDir = join(tmpdir(), `kit-doctor-test-${process.pid}-9`);
await mkdir(tmpDir, { recursive: true });
Expand Down Expand Up @@ -363,3 +378,31 @@ describe("runDoctor — keyless credentials row (Pillar 2 tail)", () => {
assert.match(row.detail, /require signed requests/);
});
});

describe("triageGateStatus (pure — pre-commit gate posture)", () => {
it("pass when both triage gates are wired into the pre-commit hook", () => {
const hook =
"#!/bin/sh\nkit security scan-staged\nkit triage check-deps\nkit triage check-skills\n";
const r = triageGateStatus(hook);
assert.equal(r.status, "pass");
assert.match(r.detail, /check-deps \+ check-skills/);
});

it("warn (partial drift) when only check-deps is wired — names the missing gate", () => {
const r = triageGateStatus("#!/bin/sh\nkit triage check-deps\n");
assert.equal(r.status, "warn");
assert.match(r.detail, /missing check-skills/);
});

it("warn (partial drift) when only check-skills is wired", () => {
const r = triageGateStatus("#!/bin/sh\nkit triage check-skills\n");
assert.equal(r.status, "warn");
assert.match(r.detail, /missing check-deps/);
});

it("skip when neither gate is present or there is no hook (never silent — suggests setup)", () => {
assert.equal(triageGateStatus("#!/bin/sh\nkit security scan-staged\n").status, "skip");
assert.equal(triageGateStatus(null).status, "skip");
assert.match(triageGateStatus(null).detail, /kit setup --recommended/);
});
});
54 changes: 54 additions & 0 deletions src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,59 @@ async function checkDeepSkillScanner(): Promise<DoctorCheck> {
: { name, status: "skip", detail: s.detail, category };
}

/**
* Triage pre-commit gate posture (increment 2d). Reports whether the commit-time triage chokepoint
* (`kit triage check-deps` + `kit triage check-skills`) is actually wired into the repo's pre-commit
* hook — the honest counterpart to `kit setup --recommended` installing it. Never silent:
* pass both triage gates present in the pre-commit hook
* warn the hook exists but is missing one gate (partial — e.g. wired before check-skills shipped)
* skip not a git repo, or the gates aren't wired (optional; run `kit setup --recommended`)
* Pure decision split out for testing.
*/
export function triageGateStatus(hookContent: string | null): {
status: DoctorCheckStatus;
detail: string;
} {
const has = (needle: string) => !!hookContent && hookContent.includes(needle);
const deps = has("triage check-deps");
const skills = has("triage check-skills");
if (deps && skills) {
return { status: "pass", detail: "pre-commit runs triage check-deps + check-skills" };
}
if (deps || skills) {
return {
status: "warn",
detail: `pre-commit wires only triage ${deps ? "check-deps" : "check-skills"} — missing ${
deps ? "check-skills" : "check-deps"
}; re-run 'kit setup --recommended'`,
};
}
return {
status: "skip",
detail:
"triage pre-commit gates not wired — run 'kit setup --recommended' to enforce dep/skill triage at commit time",
};
}

async function checkTriageGates(cwd: string): Promise<DoctorCheck> {
const name = "triage pre-commit gates";
const category = "security";
const { isGitRepository } = await import("./check-hooks.js");
if (!isGitRepository()) {
return { name, status: "skip", detail: "not a git repository", category };
}
const { resolveHooksDir } = await import("./hooks.js");
const hookPath = join(resolveHooksDir(join(cwd, ".git")), "pre-commit");
let content: string | null = null;
try {
content = await readFile(hookPath, "utf-8");
} catch {
content = null; // no pre-commit hook → gates not wired
}
const { status, detail } = triageGateStatus(content);
return { name, status, detail, category };
}

/**
* Keyless-credential posture (Pelare 2 tail — "sign, don't store"). Reports whether any hosts are
* declared keyless (`[scope].sign`) and whether kit can actually sign for them — never silent:
Expand Down Expand Up @@ -507,6 +560,7 @@ export async function runDoctor(config: kitConfig, cwd: string): Promise<DoctorR
allChecks.push(await checkBrokerRuntime(cwd));
allChecks.push(await checkKeyless(cwd));
allChecks.push(await checkDeepSkillScanner());
allChecks.push(await checkTriageGates(cwd));
allChecks.push(checkControlPlane(cwd));

const passed = allChecks.filter((c) => c.status === "pass").length;
Expand Down
Loading