Compare commits

...
3 changed files with 81 additions and 127 deletions

No files matched your search

+17 -122
View File
@@ -1,31 +1,15 @@
name: Tests
# Builds, type-checks and runs every test suite on a clean GitHub runner, and records the file
# list each published package would contain. Each suite is its own job so one failure does not
# hide the others. No provider credentials or operator configuration are supplied.
# Package suites deny external networking; scenario runtime has no external route.
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
on: workflow_dispatch
permissions:
contents: read
concurrency:
group: tests-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-package:
compact-audit:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
ref: c601bee644d44fb22f26436ceb6d8078332a9204
persist-credentials: false
- uses: actions/setup-node@v4
with:
@@ -33,110 +17,21 @@ jobs:
cache: npm
- run: npm ci
- run: npm run build
- name: Record the published file list of each package
- name: Pending compaction stage progress regression
shell: bash
run: |
set -euo pipefail
mkdir -p pack-lists
for p in cli daemon tui; do
(cd packages/$p && npm pack --dry-run --json --ignore-scripts) \
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{for(const f of JSON.parse(s)[0].files)console.log(f.path)})' \
| sort > pack-lists/$p.txt
echo "$p: $(wc -l < pack-lists/$p.txt) files"
done
- uses: actions/upload-artifact@v4
with:
name: pack-lists
path: pack-lists/
typecheck:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run lint
repo-checks:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run test:repo
package-tests:
if: ${{ github.event_name != 'push' }}
# macOS, the platform OpenRig runs on: several daemon and cli tests read macOS ps columns,
# file-inode behaviour and release tags.
runs-on: macos-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
package: [daemon, cli, tui, ui]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: brew install tmux
- run: npm ci
- name: Build the packages the tests import
run: npm run build
- name: Run the suite without ambient credentials or external network
run: |
suite_root=$(mktemp -d "$RUNNER_TEMP/opr-test.XXXXXX")
suite_root=$(cd "$suite_root" && pwd -P)
mkdir -p "$suite_root/home" "$suite_root/bin"
# Same system bytes, nonprivileged mode; no system file is changed.
/usr/bin/install -m 0755 /bin/ps "$suite_root/bin/ps"
# Only this job's temporary sockets (including tmux) are reachable.
env -i HOME="$suite_root/home" PATH="$PATH" TMPDIR="$suite_root" TMUX_TMPDIR="$suite_root" \
CI=true TERM=xterm-256color \
sandbox-exec -D IPC_ROOT="$suite_root" -p '(version 1)(allow default)(deny network-outbound)(allow network-outbound (remote ip "localhost:*"))(allow network-outbound (subpath (param "IPC_ROOT")))' \
/bin/bash -s "${{ matrix.package }}" <<'SUITE'
set -euo pipefail
node scripts/ci-macos-process-probe.mjs
# The production readers use bare ps. Select real system bytes only after
# self/owned-child observation and network/IPC confinement are proved.
export PATH="$TMPDIR/bin:$PATH"
test "$(command -v ps)" = "$TMPDIR/bin/ps"
exec npm run test -w "packages/$1"
SUITE
installed-scenario:
runs-on: ubuntu-latest
timeout-minutes: 35
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- name: Installed package, daemon restart, and seeded durability failure
run: bash scripts/run-pr-scenarios.sh
set +e
set -uo pipefail
mkdir -p proof
git rev-parse HEAD HEAD^{tree} > proof/source.txt
npm --workspace @openrig/daemon test -- test/claude-compaction-enforcer.test.ts test/context-monitor.test.ts --reporter=verbose 2>&1 | tee proof/daemon.log
result=${PIPESTATUS[0]}
git diff --exit-code > proof/source-unchanged.txt
printf 'daemon=%s\n' "$result" > proof/exits.txt
test "$result" -eq 0
- uses: actions/upload-artifact@v4
if: always()
with:
name: installed-scenario-evidence
path: dist/pr-scenarios/
name: compact-audit-red
path: proof/
if-no-files-found: error
@@ -441,6 +441,41 @@ describe("ClaudeCompactionEnforcer", () => {
expect(await belowTick(enforcer)).toEqual({ triggered: true }); // no resolver -> gate inert -> drains
});
it.each(["busy", "retained"])("a fresh high sample retains the exact owed stage after %s", async kind => {
const { enforcer, send } = await queueStageWithGen("same-generation");
const highTick = () => enforcer.maybeAutoCompact({ sessionName: "claude-seat@rig", runtime: "claude-code",
usedPercentage: 95, transcriptPath: "/tmp/c.jsonl" });
const deliveredBefore = send.mock.calls.length;
// The initial boundary advances while high; the restore must still respect delivery admission.
expect(await highTick()).toEqual({ triggered: true });
const held = kind === "busy" ? { ok: false, reason: "wait_for_idle_timeout" } : { ok: true, outcome: "retained" };
send.mockResolvedValueOnce(held);
expect(await highTick()).toEqual({ triggered: false, reason: "send_failed" });
expect(send.mock.calls.at(-1)?.[1]).toContain("restoring this Claude session after compaction");
expect(send.mock.calls.at(-1)?.[2]).toEqual({ waitForIdleMs: expect.any(Number) });
expect(await highTick()).toEqual({ triggered: true });
expect(send.mock.calls.at(-1)?.[1]).toContain("restoring this Claude session after compaction");
expect(await highTick()).toEqual({ triggered: true });
expect(send.mock.calls.at(-1)?.[1]).toContain("Now audit your compaction restore");
expect(send.mock.calls.slice(deliveredBefore).some(call => String(call[1]).includes("preparation is now required") || String(call[1]).startsWith("/compact"))).toBe(false);
});
it.each(["disabled", "replacement"])("a fresh high sample preserves the pending-stage %s gate", async kind => {
const policy = { ...POLICY_ENABLED_AT_80 };
const { transport, send } = makeSessionTransport();
let generation = "original";
const enforcer = new ClaudeCompactionEnforcer(makeSettingsStore(policy), transport, {
resolveOccupantGeneration: () => generation,
});
const tick = () => enforcer.maybeAutoCompact({ sessionName: "claude-seat@rig", runtime: "claude-code", usedPercentage: 95 });
await tick(); await tick();
const count = send.mock.calls.length;
if (kind === "disabled") policy.enabled = false;
else generation = "replacement";
expect(await tick()).toEqual({ triggered: false, reason: kind === "disabled" ? "disabled" : "stale_generation" });
expect(send).toHaveBeenCalledTimes(count);
});
// A pending post-compact stage drains without a usage sample (ContextMonitor calls this when the
// latest sample is stale or unknown). A sample-less call never starts a compaction.
const drainTick = (enforcer: ClaudeCompactionEnforcer) =>
+29 -5
View File
@@ -150,10 +150,10 @@ describe("ContextMonitor", () => {
sampled_at: new Date().toISOString(),
};
function installRealCompactionEnforcer() {
function installRealCompactionEnforcer(threshold = 80) {
const settings = new SettingsStore(join(tmpDir, "settings.json"));
settings.set("policies.claude_compaction.enabled", "true");
settings.set("policies.claude_compaction.threshold_percent", "80");
settings.set("policies.claude_compaction.threshold_percent", String(threshold));
const send = vi.fn(async (_session: string, text: string) => {
const marker = text.match(/<!-- openrig-compaction-complete .*? -->/)?.[0];
const target = text.match(/Write this attempt's complete restore map to ("(?:[^"\\]|\\.)*")/);
@@ -186,14 +186,14 @@ describe("ContextMonitor", () => {
// Bring a seat to the point just after /compact: fresh 80% usage sends the preparation prompt,
// then the next tick sends /compact, leaving the post-compact turn boundary pending.
async function compactFreshSeat(sessionName: string, now: number) {
const send = installRealCompactionEnforcer();
async function compactFreshSeat(sessionName: string, now: number, threshold = 80) {
const send = installRealCompactionEnforcer(threshold);
const writeUsage = (percentage: number, sampledAt: number) => writeSidecar(sessionName, {
...VALID_SIDECAR,
sampled_at: new Date(sampledAt).toISOString(),
context_window: { ...VALID_SIDECAR.context_window, used_percentage: percentage, remaining_percentage: 100 - percentage },
});
writeUsage(80, now);
writeUsage(threshold, now);
await monitor.pollOnce();
expect(send).toHaveBeenCalledTimes(1);
expect(send.mock.calls[0]?.[1]).toContain("OpenRig automatic compaction preparation is now required");
@@ -251,6 +251,30 @@ describe("ContextMonitor", () => {
expect(texts.some((text) => text.includes("preparation is now required") || text.startsWith("/compact"))).toBe(false);
});
it("drains the owed restore and audit on fresh usage above a low threshold, without a second compact", async () => {
let now = Date.parse("2026-10-02T12:00:00Z");
vi.spyOn(Date, "now").mockImplementation(() => now);
const { node, sessionName } = seedClaudeNode();
const { send, writeUsage } = await compactFreshSeat(sessionName, now, 9);
writeUsage(15, now);
for (let i = 0; i < 3; i++) await monitor.pollOnce();
expect(store.getForNode(node.id, sessionName).fresh).toBe(true);
const texts = send.mock.calls.slice(2).map(call => call[1]);
expect(texts).toHaveLength(3);
expect(texts[0]).toContain("OpenRig post-compaction turn boundary.");
expect(texts[1]).toContain("restoring this Claude session after compaction");
expect(texts[2]).toContain("Now audit your compaction restore");
// Even after the cooldown, sustained high usage must not re-arm the trigger.
now += 11 * 60_000;
writeUsage(15, now);
await monitor.pollOnce();
expect(send).toHaveBeenCalledTimes(5);
writeUsage(1, now); await monitor.pollOnce();
writeUsage(15, now); await monitor.pollOnce();
expect(send).toHaveBeenCalledTimes(6);
expect(send.mock.calls[5]?.[1]).toContain("preparation is now required");
});
it("an unknown sample with nothing pending triggers nothing", async () => {
seedClaudeNode();
const send = installRealCompactionEnforcer();