Skip to content
Open
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
22 changes: 19 additions & 3 deletions scripts/add-lang/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
# broken extractor); set FORCE_AB=1 to run it anyway.
#
# Usage: bench.sh <lang> <repo-name> <repo-url> "<question>" [headless|tmux|all]
# Env: CORPUS corpus dir (default /tmp/codegraph-corpus, shared with agent-eval)
# Env: CORPUS corpus dir (default /tmp/codegraph-corpus, shared with agent-eval)
# CODEGRAPH_BIN path to the codegraph binary or dist/bin/codegraph.js —
# bypasses the PATH lookup (needed on Windows, where the
# npm shim isn't directly exec-able from Node children)
set -uo pipefail

LANG_TOKEN="${1:?usage: bench.sh <lang> <repo-name> <repo-url> \"<question>\" [mode]}"
Expand All @@ -23,10 +26,23 @@ AGENT_EVAL="$(cd "$HARNESS/../agent-eval" && pwd)"
CORPUS="${CORPUS:-/tmp/codegraph-corpus}"
REPO="$CORPUS/$NAME"

command -v codegraph >/dev/null || { echo "no codegraph on PATH (build + ./scripts/local-install.sh first)"; exit 1; }
# CODEGRAPH_BIN overrides the PATH lookup; the function shadows the `codegraph`
# command for the rest of the script, and the export lets verify-extraction.mjs
# (a Node child) resolve the same binary.
if [ -n "${CODEGRAPH_BIN:-}" ]; then
export CODEGRAPH_BIN
case "$CODEGRAPH_BIN" in
*.js|*.mjs|*.cjs) codegraph() { node "$CODEGRAPH_BIN" "$@"; } ;;
*) codegraph() { "$CODEGRAPH_BIN" "$@"; } ;;
esac
CODEGRAPH_DESC="$CODEGRAPH_BIN"
else
command -v codegraph >/dev/null || { echo "no codegraph on PATH (build + ./scripts/local-install.sh first, or set CODEGRAPH_BIN)"; exit 1; }
CODEGRAPH_DESC="$(command -v codegraph)"
fi

echo "==================== add-lang bench: $NAME ($LANG_TOKEN) ===================="
echo "codegraph: $(command -v codegraph) -> $(codegraph --version 2>/dev/null || echo '?')"
echo "codegraph: $CODEGRAPH_DESC -> $(codegraph --version 2>/dev/null || echo '?')"

# 1. Ensure the repo (shallow clone, reuse if present).
mkdir -p "$CORPUS"
Expand Down
40 changes: 38 additions & 2 deletions scripts/add-lang/verify-extraction.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,60 @@
//
// Usage: node scripts/add-lang/verify-extraction.mjs <repo-path> <lang>
// Reads `codegraph status <repo> --json` using whatever codegraph is on PATH,
// so it reflects the binary that built the index.
// so it reflects the binary that built the index. Set CODEGRAPH_BIN to a
// specific binary (or to dist/bin/codegraph.js) to bypass the PATH lookup —
// on Windows, npm installs codegraph as a .cmd shim that execFileSync can't
// launch by bare name, so the lookup below resolves the shim itself.
//
// Exit codes: 0 = pass or soft-warn, 1 = critical fail, 2 = could not run.

import { execFileSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import path from 'node:path';

const [repo, lang] = process.argv.slice(2);
if (!repo || !lang) {
console.error('usage: verify-extraction.mjs <repo-path> <lang>');
process.exit(2);
}

function resolveCodegraphBin() {
if (process.env.CODEGRAPH_BIN) return process.env.CODEGRAPH_BIN;
if (process.platform !== 'win32') return 'codegraph';
// Windows: find the npm shim on PATH ourselves. The extensionless shim is a
// sh script (Git Bash only); .cmd/.exe are what a Node child can run.
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
if (!dir) continue;
for (const ext of ['.cmd', '.exe', '.bat']) {
const candidate = path.join(dir, `codegraph${ext}`);
if (existsSync(candidate)) return candidate;
}
}
return 'codegraph';
}

function runCodegraph(args) {
const bin = resolveCodegraphBin();
const ext = path.extname(bin).toLowerCase();
if (ext === '.js' || ext === '.mjs' || ext === '.cjs') {
return execFileSync(process.execPath, [bin, ...args], { encoding: 'utf8' });
}
if (ext === '.cmd' || ext === '.bat') {
// Batch shims only run through cmd.exe (shell:true). Node doesn't escape
// when shell is enabled, so quote every token ourselves.
const q = (s) => (/[\s"^&|<>()]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s);
return execFileSync(q(bin), args.map(q), { encoding: 'utf8', shell: true });
}
return execFileSync(bin, args, { encoding: 'utf8' });
}

let status;
try {
const out = execFileSync('codegraph', ['status', repo, '--json'], { encoding: 'utf8' });
const out = runCodegraph(['status', repo, '--json']);
status = JSON.parse(out);
} catch (e) {
console.error(`[verify] could not read codegraph status for ${repo}: ${e.message}`);
console.error('[verify] hint: set CODEGRAPH_BIN to the codegraph binary or dist/bin/codegraph.js');
process.exit(2);
}

Expand Down