Files
gbrain/test/skillify-check.test.ts
T
Garry TanandClaude Opus 4.7 27762abb7a Merge origin/master into garrytan/gbrain-evals
Master landed significant work since this branch was cut (v0.15.x → v0.16.x →
v0.17.0 gbrain dream + runCycle → v0.18.0 multi-source brains → v0.18.1 RLS
hardening). Bumped this branch's version from the claimed 0.18.0 to 0.19.0
because master already owns 0.18.x.

Conflicts resolved:
- VERSION: 0.19.0 (was 0.18.0 on HEAD vs 0.18.1 on master)
- package.json: 0.19.0, kept all 11 eval-facing exports, merged master's
  typescript devDep + postinstall script + test script (typecheck added)
- src/core/types.ts: union of both PageType additions. Master had added
  `meeting | note`; this branch added `email | slack | calendar-event`
  for inbox/chat/calendar ingest. Final enum carries all five.
- CHANGELOG.md: renumbered the BrainBench-extraction entry to 0.19.0 and
  placed it above master's 0.18.1 RLS entry. Tweaked copy ("In v0.17 it
  lived inside this repo" → "Previously it lived inside this repo") to
  stop implying a specific version that never shipped.
- CLAUDE.md: adjusted "BrainBench in a sibling repo" heading from
  (v0.18+) → (v0.19+).
- docs/benchmarks/2026-04-18-minions-vs-openclaw-production.md:
  resolved modify-vs-delete conflict in favor of delete (the extraction).
- scripts/llms-config.ts: dropped the docs/benchmarks/ entry (directory
  no longer exists here; lives in gbrain-evals).
- llms.txt / llms-full.txt: regenerated after the config change.
- bun.lock: accepted master's (master already dropped pdf-parse as a
  drive-by; aligned with our removal).

Tests: 2094 pass, 236 skip, 18 fail. Spot-checked failures — build-llms,
dream, orphans tests all pass in isolation. Failures reproduce only under
full-suite parallel load and are pre-existing master flakiness (matches the
graph-quality flake noted in the earlier summary). Not merge-introduced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 10:45:02 -07:00

167 lines
6.5 KiB
TypeScript

/**
* Tests for scripts/skillify-check.ts.
*
* Covers:
* - Runs against a known-well-skilled file (publish.ts) and produces a
* result object with score > 0.
* - --json emits parseable JSON with the expected shape.
* - --recent runs without crashing and returns an array of results.
* - A bogus target path reports required gaps (missing code file, etc.).
*/
import { describe, test, expect } from 'bun:test';
import { execFileSync } from 'child_process';
import { join } from 'path';
const REPO = join(__dirname, '..');
const SCRIPT = join(REPO, 'scripts', 'skillify-check.ts');
function run(args: string[]): { exitCode: number; stdout: string; stderr: string } {
try {
const stdout = execFileSync('bun', ['run', SCRIPT, ...args], {
encoding: 'utf-8',
stdio: ['ignore', 'pipe', 'pipe'],
cwd: REPO,
});
return { exitCode: 0, stdout, stderr: '' };
} catch (err: any) {
return {
exitCode: err.status ?? 1,
stdout: err.stdout?.toString?.() ?? '',
stderr: err.stderr?.toString?.() ?? '',
};
}
}
describe('skillify-check CLI', () => {
test('text mode runs against a known-skilled file', () => {
// publish is one of the gbrain commands with SKILL.md + tests +
// resolver entry. Should get a non-zero score.
const result = run(['src/commands/publish.ts']);
expect(result.stdout).toContain('[publish]');
expect(result.stdout).toContain('SKILL.md exists');
expect(result.stdout).toContain('Unit tests');
expect(result.stdout).toContain('Resolver entry');
// Score format: "N/10"
expect(result.stdout).toMatch(/\d+\/\d+/);
});
test('--json emits a parseable array with the expected shape', () => {
const result = run(['src/commands/publish.ts', '--json']);
expect(result.stdout.trim()).toMatch(/^\[/);
const parsed = JSON.parse(result.stdout);
expect(Array.isArray(parsed)).toBe(true);
expect(parsed.length).toBe(1);
const r = parsed[0];
expect(r.path).toBe('src/commands/publish.ts');
expect(r.skillName).toBe('publish');
expect(Array.isArray(r.items)).toBe(true);
expect(r.items.length).toBeGreaterThanOrEqual(10);
expect(typeof r.score).toBe('number');
expect(typeof r.total).toBe('number');
expect(typeof r.recommendation).toBe('string');
// Every item has the expected keys
for (const item of r.items) {
expect(typeof item.name).toBe('string');
expect(typeof item.passed).toBe('boolean');
expect(typeof item.required).toBe('boolean');
}
});
test('--recent produces JSON with results for recent files', () => {
const result = run(['--recent', '--json']);
// --recent may find zero files on a cold clone; either way JSON must parse.
const parsed = JSON.parse(result.stdout);
expect(Array.isArray(parsed)).toBe(true);
// If any results returned, they must have the expected shape.
if (parsed.length > 0) {
expect(typeof parsed[0].score).toBe('number');
expect(typeof parsed[0].recommendation).toBe('string');
}
});
test('bogus target reports `Code file exists: false` as a required gap', () => {
const result = run(['src/definitely-not-a-real-file.ts', '--json']);
const parsed = JSON.parse(result.stdout);
const codeCheck = parsed[0].items.find((i: any) => i.name === 'Code file exists');
expect(codeCheck.passed).toBe(false);
expect(codeCheck.required).toBe(true);
// Overall recommendation should flag the gap.
expect(parsed[0].recommendation).toMatch(/skillify|create|missing/);
// Exit code non-zero
expect(result.exitCode).toBe(1);
});
});
// ---------------------------------------------------------------------------
// check-resolvable wiring (per plan-eng-review — no silent pass on missing binary)
// ---------------------------------------------------------------------------
import { mkdtempSync, writeFileSync, chmodSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { spawnSync } from 'child_process';
import { afterEach } from 'bun:test';
function runWithPath(opts: { path: string }): { stdout: string; stderr: string } {
// Use bun's absolute path so spawnSync doesn't need bun on the scoped PATH.
// PATH is what skillify-check's own `spawnSync('gbrain', ...)` will search.
const bunBin = process.execPath || 'bun';
const res = spawnSync(bunBin, ['run', SCRIPT, '--json', 'src/commands/publish.ts'], {
encoding: 'utf-8',
cwd: REPO,
env: { ...process.env, PATH: opts.path },
maxBuffer: 10 * 1024 * 1024,
});
return {
stdout: res.stdout ?? '',
stderr: res.stderr ?? '',
};
}
describe('skillify-check ↔ gbrain check-resolvable wiring', () => {
const created: string[] = [];
afterEach(() => {
while (created.length) {
const p = created.pop()!;
try { rmSync(p, { recursive: true, force: true }); } catch { /* ignore */ }
}
});
test('loud failure when gbrain binary is not on PATH (no silent pass)', () => {
const emptyPath = mkdtempSync(join(tmpdir(), 'no-gbrain-'));
created.push(emptyPath);
const r = runWithPath({ path: emptyPath });
// Loud warning must appear on stderr.
expect(r.stderr).toContain('gbrain check-resolvable not runnable');
const parsed = JSON.parse(r.stdout);
const gate = parsed[0].items.find((i: any) => i.name === 'check-resolvable gate');
expect(gate).toBeDefined();
// Gate MUST NOT pass when the binary is unavailable.
expect(gate.passed).toBe(false);
expect(gate.detail).toContain('unavailable');
});
test('happy path: synthetic gbrain on PATH returns ok=true, gate passes', () => {
const fakeBinDir = mkdtempSync(join(tmpdir(), 'fake-gbrain-'));
created.push(fakeBinDir);
const fakeBin = join(fakeBinDir, 'gbrain');
writeFileSync(
fakeBin,
`#!/bin/sh
cat <<'JSON'
{"ok":true,"skillsDir":"/fake","report":{"ok":true,"issues":[],"summary":{"total_skills":0,"reachable":0,"unreachable":0,"overlaps":0,"gaps":0}},"autoFix":null,"deferred":[{"check":5,"name":"trigger_routing_eval","issue":""},{"check":6,"name":"brain_filing","issue":""}],"error":null,"message":null}
JSON
`,
);
chmodSync(fakeBin, 0o755);
const r = runWithPath({ path: `${fakeBinDir}:${process.env.PATH}` });
// No silent-pass warning.
expect(r.stderr).not.toContain('gbrain check-resolvable not runnable');
const parsed = JSON.parse(r.stdout);
const gate = parsed[0].items.find((i: any) => i.name === 'check-resolvable gate');
expect(gate).toBeDefined();
expect(gate.passed).toBe(true);
expect(gate.detail).toContain('all skill-tree checks pass');
});
});