Compare commits

...
4 changed files with 139 additions and 124 deletions

No files matched your search

+12 -122
View File
@@ -1,28 +1,12 @@
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:
permissions:
contents: read
concurrency:
group: tests-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-package:
attach-name-regression:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
@@ -32,111 +16,17 @@ jobs:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
- name: Record the published file list of each package
- run: npm run build -w packages/daemon
- name: Check whether a logical reply address reaches a raw tmux binding
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
mkdir evidence
set +e
npm run test -w packages/daemon -- test/self-attach-reply-address.test.ts --reporter=json --outputFile="$GITHUB_WORKSPACE/evidence/reply-address.json" > evidence/reply-address.log 2>&1
code=$?
printf '%s\n' "$code" > evidence/reply-address.exit
test "$code" -eq 1
- uses: actions/upload-artifact@v4
if: always()
with:
name: installed-scenario-evidence
path: dist/pr-scenarios/
if-no-files-found: error
name: attach-name-evidence
path: evidence/
+1 -2
View File
@@ -112,6 +112,7 @@ export function attachCommand(depsOverride?: StatusDeps): Command {
cwd: opts.cwd ?? process.cwd(),
};
if (opts.runtime) body["runtime"] = opts.runtime;
if (opts.displayName) body["displayName"] = opts.displayName;
const attachContext = resolveAttachContext();
body["attachmentType"] = attachContext.attachmentType;
@@ -119,8 +120,6 @@ export function attachCommand(depsOverride?: StatusDeps): Command {
body["tmuxSession"] = attachContext.tmuxSession;
if (attachContext.tmuxWindow) body["tmuxWindow"] = attachContext.tmuxWindow;
body["tmuxPane"] = attachContext.tmuxPane;
} else if (opts.displayName) {
body["displayName"] = opts.displayName;
}
if (hasNode) {
+38
View File
@@ -1,5 +1,8 @@
import { describe, it, expect, vi, beforeAll, afterAll } from "vitest";
import http from "node:http";
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Command } from "commander";
import { attachCommand, resolveAttachContext } from "../src/commands/attach.js";
import { DaemonClient } from "../src/client.js";
@@ -131,6 +134,41 @@ describe("Attach CLI", () => {
expect(receivedBody).toMatchObject({ logicalId: "orch1.lead", runtime: "codex" });
});
it.each([
["--node", "orch1.lead"],
["--pod", "orch1", "--member", "lead", "--runtime", "codex"],
])("forwards --display-name from tmux in %s mode without changing its physical target", async (...target) => {
const bin = mkdtempSync(join(tmpdir(), "openrig-attach-tmux-"));
const savedPane = process.env["TMUX_PANE"];
const savedPath = process.env["PATH"];
writeFileSync(join(bin, "tmux"), "#!/bin/sh\nprintf '0\\n@12\\n%%42\\n'\n");
chmodSync(join(bin, "tmux"), 0o755);
process.env["TMUX_PANE"] = "%42";
process.env["PATH"] = `${bin}:${savedPath ?? ""}`;
try {
const { exitCode } = await captureLogs(async () => {
await makeCmd().parseAsync([
"node", "rig", "attach", "--self", "--rig", "rig-1", ...target,
"--display-name", "Taylor",
]);
});
expect(exitCode).toBeUndefined();
expect(receivedBody).toMatchObject({
displayName: "Taylor",
attachmentType: "tmux",
tmuxSession: "0",
tmuxWindow: "@12",
tmuxPane: "%42",
});
} finally {
if (savedPane === undefined) delete process.env["TMUX_PANE"];
else process.env["TMUX_PANE"] = savedPane;
if (savedPath === undefined) delete process.env["PATH"];
else process.env["PATH"] = savedPath;
rmSync(bin, { recursive: true, force: true });
}
});
it("attach --self --print-env prints shell exports only", async () => {
const { logs, exitCode } = await captureLogs(async () => {
await makeCmd().parseAsync(["node", "rig", "attach", "--self", "--rig", "rig-1", "--node", "orch1.lead", "--print-env"]);
@@ -0,0 +1,88 @@
import { describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import { createDb } from "../src/db/connection.js";
import { migrate } from "../src/db/migrate.js";
import { ALL_MIGRATIONS } from "../src/db/all-migrations.js";
import { RigRepository } from "../src/domain/rig-repository.js";
import { PodRepository } from "../src/domain/pod-repository.js";
import { SessionRegistry } from "../src/domain/session-registry.js";
import { EventBus } from "../src/domain/event-bus.js";
import { SelfAttachService } from "../src/domain/self-attach-service.js";
import { SessionTransport } from "../src/domain/session-transport.js";
import type { TmuxAdapter } from "../src/adapters/tmux.js";
import { rigsRoutes } from "../src/routes/rigs.js";
import { transportRoutes } from "../src/routes/transport.js";
import { wrapPaneEnvelope } from "../src/lib/pane-envelope.js";
describe("self-attach logical reply address", () => {
it.each(["0", "person-terminal"])("routes the logical From address to the unchanged %s tmux binding", async (physicalSession) => {
const db = createDb();
try {
migrate(db, ALL_MIGRATIONS);
const rigRepo = new RigRepository(db);
const podRepo = new PodRepository(db);
const sessionRegistry = new SessionRegistry(db);
const eventBus = new EventBus(db);
const rig = rigRepo.createRig("sample-team");
const node = rigRepo.addNode(rig.id, "person.agent", { runtime: "terminal" });
const paneWrites: Array<{ target: string; pane: string; text: string }> = [];
const sendText = vi.fn(async (target: string, text: string) => {
if (target !== physicalSession) throw new Error("unexpected physical target");
paneWrites.push({ target, pane: "%42", text });
return { ok: true as const };
});
const tmux = {
hasSession: async (name: string) => name === physicalSession,
probeSession: async (name: string) => ({ state: name === physicalSession ? "present" : "absent" }),
capturePaneContent: async () => "plain terminal",
getPaneCommand: async () => "sh",
sendText,
sendKeys: vi.fn(async () => ({ ok: true as const })),
} as unknown as TmuxAdapter;
const service = new SelfAttachService({ db, rigRepo, podRepo, sessionRegistry, eventBus, tmuxAdapter: tmux });
const transport = new SessionTransport({ db, rigRepo, sessionRegistry, tmuxAdapter: tmux, sleep: async () => {} });
const app = new Hono();
app.use("*", async (c, next) => {
c.set("selfAttachService" as never, service);
c.set("sessionTransport" as never, transport);
await next();
});
app.route("/api/rigs", rigsRoutes);
app.route("/api/transport", transportRoutes());
const attach = await app.request(`/api/rigs/${rig.id}/attach-self`, {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ logicalId: "person.agent", displayName: "Taylor", attachmentType: "tmux",
tmuxSession: physicalSession, tmuxWindow: "@12", tmuxPane: "%42" }),
});
expect(attach.status).toBe(201);
const attached = await attach.json();
expect(sessionRegistry.getBindingForNode(node.id)?.tmuxSession).toBe(physicalSession);
// The proposed logical identity is substituted only in the envelope here. No alias is installed.
const proposedSender = "person-agent@sample-team";
const envelope = wrapPaneEnvelope(proposedSender, "operator@sample-team", "hello");
const from = envelope.split("\n")[0]!.slice("From: ".length);
expect(envelope).toContain(`rig send ${from} "..."`);
const send = (session: string) => app.request("/api/transport/send", {
method: "POST", headers: { "Content-Type": "application/json", "X-OpenRig-Session": "operator@sample-team" },
body: JSON.stringify({ session, text: "harmless reply" }),
});
const logicalResolution = await transport.resolveSessions({ session: from });
const logicalReply = await send(from);
const logicalBody = await logicalReply.json();
expect(paneWrites).toEqual([]);
const physicalReply = await send(attached.env.OPENRIG_SESSION_NAME);
const physicalBody = await physicalReply.json();
expect(physicalReply.status).toBe(200);
expect(physicalBody.ok).toBe(true);
expect(paneWrites).toEqual([{ target: physicalSession, pane: "%42", text: "harmless reply" }]);
console.info(JSON.stringify({ physicalSession, attachedName: attached.env.OPENRIG_SESSION_NAME,
proposedFrom: from, logicalResolution, logicalStatus: logicalReply.status, logicalBody,
physicalStatus: physicalReply.status, paneWrites }));
// This is the required acceptance check: the exact logical From/reply address must reach this pane.
expect(logicalReply.status).toBe(200);
} finally {
db.close();
}
});
});