Address CodeRabbit review

- The skill told agents both to never put a pairing URL in a response and
  to hand the shared one to the user. State the rule and its single
  exception explicitly: give the URL to the person who asked for access,
  never put it anywhere durable.
- A failed `tailscale serve` left the port unshared, because the stale-
  mapping clear had already run. The clear is still required (old
  mappings carry path routes that serving "/" would not replace), so say
  so in the error instead of letting an operator assume the previous
  mapping survived.
- Worktree-derived ports were described as collision-free. They are a
  preferred offset, not a guarantee — hashes can collide and occupied
  ports shift both values. Qualified in AGENTS.md, the skill, and
  docs/reference/scripts.md.

CodeRabbit also asked for tests around the pairing-url command; those
landed in 0555604de, which it had not yet seen.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5 committed 2026-07-24 17:38:23 -07:00
1 parent 0555604ded
commit 827469be4d
5 files changed
+95 -11

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
import { assert, describe, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Sink from "effect/Sink";
import * as Stream from "effect/Stream";
import { ChildProcessSpawner } from "effect/unstable/process";
import { DevShareError, shareDevServer } from "./dev-share.ts";
const TAILNET_STATUS = JSON.stringify({ Self: { DNSName: "host.example.ts.net." } });
/**
* Answers `tailscale status --json` with a valid tailnet name, and lets each
* test decide how the `serve` call behaves.
*/
const spawnerLayer = (serve: { readonly exitCode: number; readonly stderr?: string }) =>
Layer.succeed(
ChildProcessSpawner.ChildProcessSpawner,
ChildProcessSpawner.make((command) => {
const args = "args" in command ? (command.args as ReadonlyArray<string>) : [];
const isStatus = args.includes("status");
return Effect.succeed(
ChildProcessSpawner.makeHandle({
pid: ChildProcessSpawner.ProcessId(1),
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(isStatus ? 0 : serve.exitCode)),
isRunning: Effect.succeed(false),
kill: () => Effect.void,
unref: Effect.succeed(Effect.void),
stdin: Sink.drain,
stdout: isStatus ? Stream.make(new TextEncoder().encode(TAILNET_STATUS)) : Stream.empty,
stderr:
!isStatus && serve.stderr
? Stream.make(new TextEncoder().encode(serve.stderr))
: Stream.empty,
all: Stream.empty,
getInputFd: () => Sink.drain,
getOutputFd: () => Stream.empty,
}),
);
}),
);
describe("shareDevServer", () => {
it.effect("returns the tailnet URL for the same port", () =>
Effect.gen(function* () {
const shared = yield* shareDevServer({ webPort: 5788 }).pipe(
Effect.provide(spawnerLayer({ exitCode: 0 })),
);
assert.equal(shared.host, "host.example.ts.net");
assert.equal(shared.url, "https://host.example.ts.net:5788/");
}),
);
// The stale-mapping clear runs before serve, so a failure here leaves the
// port serving nothing. Saying only "serve failed" would let an operator
// assume their previous mapping survived.
it.effect("reports that the prior mapping was cleared when serve fails", () =>
Effect.gen(function* () {
const error: DevShareError = yield* shareDevServer({ webPort: 5788 }).pipe(
Effect.provide(spawnerLayer({ exitCode: 1, stderr: "port already in use" })),
Effect.flip,
);
assert.equal(error.reason, "serve-failed");
assert.include(error.message, "port already in use");
assert.include(error.message, "no longer served");
assert.include(error.message, "5788");
}),
);
});
+8 -3
View File
@@ -153,8 +153,9 @@ export const shareDevServer = Effect.fn("devShare.shareDevServer")(function* (in
// Clear any mapping left behind by a run that was killed before its finalizer
// could fire. Serve config survives both the process and a reboot, and a
// stale entry may carry path routes we no longer want (older versions mapped
// /ws, /api and friends to a separate backend port).
// stale entry may carry path routes we no longer want — older versions mapped
// /ws, /api and friends to a separate backend port, and serving "/" alone
// would leave those pointing at a port nothing is listening on.
yield* unshareDevServer(input.webPort);
const serve = yield* runTailscale(
@@ -163,9 +164,13 @@ export const shareDevServer = Effect.fn("devShare.shareDevServer")(function* (in
);
if (serve.exitCode !== 0) {
// The clear above already happened, so say so: on a re-share this port is
// now serving nothing, and an operator who only saw "serve failed" would
// reasonably assume the previous mapping survived.
const cause = serve.stderr.trim() || `exit code ${String(serve.exitCode)}`;
return yield* new DevShareError({
reason: "serve-failed",
detail: serve.stderr.trim() || `exit code ${String(serve.exitCode)} for port ${port}`,
detail: `${cause} (port ${port} is no longer served; any previous mapping for it was cleared before this attempt)`,
});
}