feat: v2.0 iteration — test coverage, reliability, observability

M0: Test coverage expansion (151 → 321 tests, 61% → 66% lines)
  - normalizeKnowledge CRLF/LF normalization fix
  - gooseReviewer: 11 tests, 97.35% coverage
  - r2 storage: 22 tests, 100% coverage
  - triage processor: 11 tests, exported buildTriagePrompt/labelName
  - webhook processor: 35 tests, 72.39% coverage
  - conflict resolver: 12 tests
  - review processor: 7 tests

M1: Reliability hardening
  - Smart retry with jitter, maxTotalTimeoutMs, custom retryable predicate
  - MergeGuard: in-memory merge dedup tracker (100% coverage)
  - failureMessages: 7-category failure classifier (100% coverage)

M2: Observability
  - MetricsCollector: Actions-run metrics with snapshot/markdown/reset
  - 11 tests, 100% coverage

New files: 12 test files, 3 source modules
All gates: typecheck ✓ lint ✓ format ✓ 321/321 tests ✓ build ✓
This commit is contained in:
ghbot committed 2026-08-24 17:34:04 +08:00
1 parent db53296d78
commit 78bf8e9e41
87 files changed
+6003 -2587

No files matched your search

+31 -15
View File
@@ -1,33 +1,45 @@
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const { pathToFileURL } = require('url');
const { execFileSync } = require('child_process');
const path = require("path");
const fs = require("fs");
const { pathToFileURL } = require("url");
const { execFileSync } = require("child_process");
const dir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
const BAKED = "C:\\Users\\Administrator.DESKTOP-EGNE9ND\\AppData\\Roaming\\npm\\node_modules\\@nanonets\\graft\\dist\\claude";
const BAKED =
"C:\\Users\\Administrator.DESKTOP-EGNE9ND\\AppData\\Roaming\\npm\\node_modules\\@nanonets\\graft\\dist\\claude";
// The dist/claude dir of @nanonets/graft resolved from a base whose node_modules is searched.
function fromPkg(base) {
try {
const pkg = require.resolve('@nanonets/graft/package.json', { paths: [base] });
return path.join(path.dirname(pkg), 'dist', 'claude');
} catch { return null; }
const pkg = require.resolve("@nanonets/graft/package.json", { paths: [base] });
return path.join(path.dirname(pkg), "dist", "claude");
} catch {
return null;
}
}
// The global node_modules dir per npm (handles Homebrew/Windows/volta). Queried on demand.
function globalRoot() {
try {
const root = execFileSync('npm', ['root', '-g'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], shell: process.platform === 'win32' }).trim();
const root = execFileSync("npm", ["root", "-g"], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
shell: process.platform === "win32"
}).trim();
return root || null;
} catch { return null; /* npm unavailable */ }
} catch {
return null; /* npm unavailable */
}
}
function candidates() {
const out = [];
if (BAKED) out.push(BAKED);
const local = fromPkg(dir); if (local) out.push(local);
const legacy = fromPkg(path.join(path.dirname(process.execPath), '..', 'lib')); if (legacy) out.push(legacy);
const gr = globalRoot(); if (gr) out.push(path.join(gr, '@nanonets', 'graft', 'dist', 'claude'));
const local = fromPkg(dir);
if (local) out.push(local);
const legacy = fromPkg(path.join(path.dirname(process.execPath), "..", "lib"));
if (legacy) out.push(legacy);
const gr = globalRoot();
if (gr) out.push(path.join(gr, "@nanonets", "graft", "dist", "claude"));
return out;
}
@@ -36,7 +48,11 @@ function entry(name) {
const f = path.join(d, name);
if (fs.existsSync(f)) return f;
}
return path.join(dir, 'dist', 'claude', name); // last-ditch; import will no-op if absent
return path.join(dir, "dist", "claude", name); // last-ditch; import will no-op if absent
}
import(pathToFileURL(entry("hooks.js")).href).then((m) => m.main(process.argv[2])).catch(() => { /* graft unavailable — no-op */ });
import(pathToFileURL(entry("hooks.js")).href)
.then((m) => m.main(process.argv[2]))
.catch(() => {
/* graft unavailable — no-op */
});
+31 -15
View File
@@ -1,33 +1,45 @@
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const { pathToFileURL } = require('url');
const { execFileSync } = require('child_process');
const path = require("path");
const fs = require("fs");
const { pathToFileURL } = require("url");
const { execFileSync } = require("child_process");
const dir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
const BAKED = "C:\\Users\\Administrator.DESKTOP-EGNE9ND\\AppData\\Roaming\\npm\\node_modules\\@nanonets\\graft\\dist\\claude";
const BAKED =
"C:\\Users\\Administrator.DESKTOP-EGNE9ND\\AppData\\Roaming\\npm\\node_modules\\@nanonets\\graft\\dist\\claude";
// The dist/claude dir of @nanonets/graft resolved from a base whose node_modules is searched.
function fromPkg(base) {
try {
const pkg = require.resolve('@nanonets/graft/package.json', { paths: [base] });
return path.join(path.dirname(pkg), 'dist', 'claude');
} catch { return null; }
const pkg = require.resolve("@nanonets/graft/package.json", { paths: [base] });
return path.join(path.dirname(pkg), "dist", "claude");
} catch {
return null;
}
}
// The global node_modules dir per npm (handles Homebrew/Windows/volta). Queried on demand.
function globalRoot() {
try {
const root = execFileSync('npm', ['root', '-g'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], shell: process.platform === 'win32' }).trim();
const root = execFileSync("npm", ["root", "-g"], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
shell: process.platform === "win32"
}).trim();
return root || null;
} catch { return null; /* npm unavailable */ }
} catch {
return null; /* npm unavailable */
}
}
function candidates() {
const out = [];
if (BAKED) out.push(BAKED);
const local = fromPkg(dir); if (local) out.push(local);
const legacy = fromPkg(path.join(path.dirname(process.execPath), '..', 'lib')); if (legacy) out.push(legacy);
const gr = globalRoot(); if (gr) out.push(path.join(gr, '@nanonets', 'graft', 'dist', 'claude'));
const local = fromPkg(dir);
if (local) out.push(local);
const legacy = fromPkg(path.join(path.dirname(process.execPath), "..", "lib"));
if (legacy) out.push(legacy);
const gr = globalRoot();
if (gr) out.push(path.join(gr, "@nanonets", "graft", "dist", "claude"));
return out;
}
@@ -36,7 +48,11 @@ function entry(name) {
const f = path.join(d, name);
if (fs.existsSync(f)) return f;
}
return path.join(dir, 'dist', 'claude', name); // last-ditch; import will no-op if absent
return path.join(dir, "dist", "claude", name); // last-ditch; import will no-op if absent
}
import(pathToFileURL(entry("statusline.js")).href).then((m) => m.main()).catch(() => { /* graft unavailable — no-op */ });
import(pathToFileURL(entry("statusline.js")).href)
.then((m) => m.main())
.catch(() => {
/* graft unavailable — no-op */
});