Skip to content

Commit 2943b9c

Browse files
author
StackMemory Bot (CLI)
committed
fix: determinism score parser + pre-commit hook restructure
- Fix score extraction to handle nested report.score - Add verify-staged.sh to pre-commit pipeline - Add verification test for multimodal harness
1 parent c68bbf6 commit 2943b9c

4 files changed

Lines changed: 75 additions & 2 deletions

File tree

.husky/pre-commit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ elif [ -d "$HOME/.nvm/versions/node" ]; then
1010
fi
1111

1212
npx lint-staged
13-
npm run build
13+
bash scripts/verify-staged.sh
14+
npm run determinism:pre-commit

scripts/determinism-pre-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ printf '%s\n' "$RELEVANT_FILES" | sed 's/^/ - /'
5353

5454
REPORT_JSON="$(node --import tsx src/cli/index.ts bench determinism --task "$TASK" --runs "$RUNS" --json)"
5555

56-
SCORE="$(printf '%s' "$REPORT_JSON" | node -e "let data='';process.stdin.on('data',d=>data+=d);process.stdin.on('end',()=>{const report=JSON.parse(data);process.stdout.write(String(report.score));});")"
56+
SCORE="$(printf '%s' "$REPORT_JSON" | node -e "let data='';process.stdin.on('data',d=>data+=d);process.stdin.on('end',()=>{const stored=JSON.parse(data);const score=stored.report?.score ?? stored.score;process.stdout.write(String(score));});")"
5757

5858
if [ "$SCORE" != "100" ] && [ "$SCORE" != "100.00" ]; then
5959
log_skip "Determinism smoke failed with score $SCORE/100"

scripts/verify-staged.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
6+
cd "$ROOT"
7+
8+
if [ "${STACKMEMORY_VERIFY_SKIP:-0}" = "1" ]; then
9+
echo "[verify-staged] skipped because STACKMEMORY_VERIFY_SKIP=1"
10+
exit 0
11+
fi
12+
13+
CHANGED_FILES="${STACKMEMORY_VERIFY_FILES:-}"
14+
if [ -z "$CHANGED_FILES" ]; then
15+
CHANGED_FILES="$(git diff --cached --name-only --diff-filter=ACMR)"
16+
fi
17+
18+
if [ -z "$CHANGED_FILES" ]; then
19+
echo "[verify-staged] no staged files"
20+
exit 0
21+
fi
22+
23+
matching_paths() {
24+
printf '%s\n' "$CHANGED_FILES" | grep -E "$1" || true
25+
}
26+
27+
has_path() {
28+
printf '%s\n' "$CHANGED_FILES" | grep -E "$1" >/dev/null
29+
}
30+
31+
run_shell() {
32+
echo "[verify-staged] $*"
33+
bash -lc "$*"
34+
}
35+
36+
test_files="$(matching_paths '(^src/|^scripts/|^packages/).*((__tests__/.*)|(\.|-)test)\.ts$')"
37+
if [ -n "$test_files" ]; then
38+
run_shell "npx vitest run $(printf '%s\n' "$test_files" | xargs) --reporter=dot"
39+
fi
40+
41+
if has_path '^(src/|scripts/|packages/|templates/|Shadowbroker/|package\.json$|package-lock\.json$|tsconfig|esbuild\.config\.js$)'; then
42+
run_shell 'npm run build'
43+
fi
44+
45+
echo "[verify-staged] passed"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { mkdtempSync, rmSync } from 'fs';
3+
import { join } from 'path';
4+
import { tmpdir } from 'os';
5+
6+
import { runVerificationCommands } from '../providers.js';
7+
8+
describe('multimodal verification commands', () => {
9+
it('captures passing and failing command results', () => {
10+
const repoPath = mkdtempSync(join(tmpdir(), 'stackmemory-verify-'));
11+
12+
try {
13+
const results = runVerificationCommands(repoPath, [
14+
'node -e "console.log(\'pass-signal\')"',
15+
'node -e "console.error(\'fail-signal\'); process.exit(7)"',
16+
]);
17+
18+
expect(results).toHaveLength(2);
19+
expect(results[0]).toMatchObject({ ok: true });
20+
expect(results[0]?.output).toContain('pass-signal');
21+
expect(results[1]).toMatchObject({ ok: false });
22+
expect(results[1]?.output).toContain('fail-signal');
23+
} finally {
24+
rmSync(repoPath, { recursive: true, force: true });
25+
}
26+
});
27+
});

0 commit comments

Comments
 (0)