Compare commits

...
2 changed files with 118 additions and 122 deletions

No files matched your search

+20 -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-unconfirmed:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
ref: 4ebb13648cf046d462b0b40b94315f81eb23e002
persist-credentials: false
- uses: actions/setup-node@v4
with:
@@ -33,110 +17,24 @@ jobs:
cache: npm
- run: npm ci
- run: npm run build
- name: Record the published file list of each package
- name: Submitted compact cancellation 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
node --version > proof/node-version.txt
npm --workspace @openrig/daemon test -- test/compaction-command-submission.test.ts --reporter=verbose 2>&1 | tee proof/daemon.log
result=${PIPESTATUS[0]}
npm run lint 2>&1 | tee proof/typecheck.log
lint_result=${PIPESTATUS[0]}
git diff --exit-code > proof/source-unchanged.txt
printf 'daemon=%s\ntypecheck=%s\n' "$result" "$lint_result" > proof/exits.txt
test "$result" -eq 0 && test "$lint_result" -eq 0
- uses: actions/upload-artifact@v4
if: always()
with:
name: installed-scenario-evidence
path: dist/pr-scenarios/
name: compact-unconfirmed-r2-red
path: proof/
if-no-files-found: error
@@ -537,3 +537,101 @@ it('a real zero-input refusal through the transport (the pane is stuck in a tmux
for (let i = 0; i < 3; i++) await f.e.maybeAutoCompact(input);
expect(compactWrites(f)).toBe(0);
});
it('cancel disarms a submitted manual attempt without claiming it failed or sending input; an explicit retry uses a fresh map', async () => {
const f = fixture();
f.onSleep(() => f.stageMap());
expect(await f.e.triggerManualCompact(input, {operatorInitiated: true})).toMatchObject({triggered: true});
const previous = f.e.getPreparationState(seat)!;
const before = [...f.events];
const app = new Hono();
app.use('*', async (c, next) => {
c.set('compactionEnforcer' as never, f.e);
c.set('sessionTransport' as never, f.transport);
await next();
});
app.route('/api/compaction', compactionRoutes());
vi.spyOn(f.transport, 'resolveSessions').mockResolvedValue({ok: true, sessions: [seat]} as any);
const response = await app.request('/api/compaction/cancel', {
method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({session: seat}),
});
expect(response.status).toBe(200);
expect(await response.json()).toMatchObject({ok: true, preparation: {
attemptId: previous.attemptId, status: 'stopped', reason: 'compaction_cancelled', compact: 'submitted_unconfirmed',
}});
expect(f.e.getManualCompactionState(seat)).toMatchObject({stage: 'cancelled', reason: 'compaction_cancelled'});
expect(f.e.observedCompaction(seat)).toBeNull();
expect(f.e.hasPendingPostCompactStage(seat)).toBe(false);
expect(await f.e.drainPendingPostCompactStage(input)).toEqual({triggered: false, reason: 'no_pending_stage'});
f.advance(61_000);
await f.e.maybeAutoCompact(input);
expect(f.events).toEqual(before); // no automatic retry, restore, audit, or cancellation keystroke
expect(await f.e.triggerManualCompact(input, {operatorInitiated: true})).toMatchObject({triggered: true});
const next = f.e.getPreparationState(seat)!;
expect(next.attemptId).not.toBe(previous.attemptId);
expect(next.mapPath).not.toBe(previous.mapPath);
expect(f.texts().filter((t) => t.startsWith('/compact'))).toHaveLength(2);
});
for (const activity of ['running', 'unknown']) {
it(`cancel preserves the unconfirmed receipt, and a ${activity} pane cannot get a second /compact through a stale idle hook`, async () => {
const f = fixture();
await f.e.triggerManualCompact(input, {operatorInitiated: true, skipMap: true});
expect(f.e.cancelPreparation(seat)).toMatchObject({status: 'stopped', compact: 'submitted_unconfirmed'});
f.activity(activity);
f.hook('idle');
const retry = await f.e.triggerManualCompact(input, {operatorInitiated: true, skipMap: true});
expect(retry).toMatchObject({triggered: false, reason: activity === 'unknown' ? 'target_activity_unknown' : 'wait_for_idle_timeout'});
expect(f.texts().filter((t) => t.startsWith('/compact'))).toHaveLength(1);
expect(f.e.getPreparationState(seat)).toMatchObject({status: 'stopped', compact: 'not_sent'});
});
}
it('cancel fences a pending back-half pane read before any text or Enter can land', async () => {
const f = fixture();
await f.e.triggerManualCompact(input, {operatorInitiated: true, skipMap: true});
const before = [...f.events];
let release!: () => void;
const blocked = new Promise<void>((r) => { release = r; });
let entered!: () => void;
const reading = new Promise<void>((r) => { entered = r; });
vi.spyOn(f.transport as any, 'classifySendReadiness').mockImplementation(async () => {
entered(); await blocked; return {state: 'idle', reason: 'fixture', evidenceSource: 'fixture'};
});
const drain = f.e.drainPendingPostCompactStage(input);
await reading;
f.e.cancelPreparation(seat);
release();
await drain;
expect(f.events).toEqual(before);
expect(f.e.hasPendingPostCompactStage(seat)).toBe(false);
expect(f.e.getManualCompactionState(seat)?.stage).toBe('cancelled');
});
it('cancel after a back-half paste prevents Enter and does not resurrect the next stage', async () => {
const f = fixture();
await f.e.triggerManualCompact(input, {operatorInitiated: true, skipMap: true});
const before = f.events.length;
f.onText(() => { f.e.cancelPreparation(seat); });
await f.e.drainPendingPostCompactStage(input);
expect(f.events.slice(before).filter((ev) => ev.kind === 'keys' && ev.keys.includes('Enter'))).toEqual([]);
expect(f.e.hasPendingPostCompactStage(seat)).toBe(false);
expect(f.e.getPreparationState(seat)).toMatchObject({status: 'stopped', compact: 'submitted_unconfirmed'});
});
it('cancel after a back-half send settles prevents its late receipt from rearming restore', async () => {
const f = fixture();
await f.e.triggerManualCompact(input, {operatorInitiated: true, skipMap: true});
const real = f.transport.send.bind(f.transport);
vi.spyOn(f.transport, 'send').mockImplementation(async (...args) => {
const result = await real(...args);
f.e.cancelPreparation(seat);
return result;
});
await f.e.drainPendingPostCompactStage(input);
expect(f.e.hasPendingPostCompactStage(seat)).toBe(false);
const after = [...f.events];
await f.e.drainPendingPostCompactStage(input);
expect(f.events).toEqual(after);
});