Skip to content
Merged
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
30 changes: 28 additions & 2 deletions apps/server/src/fork/processRunnerFork.closedStdin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as Layer from "effect/Layer";
import * as PlatformError from "effect/PlatformError";
import * as Sink from "effect/Sink";
import * as Stream from "effect/Stream";
import { ChildProcessSpawner } from "effect/process";
import { ChildProcess, ChildProcessSpawner } from "effect/process";

import * as ProcessRunner from "../processRunner.ts";
import { isClosedStdin } from "./processRunnerFork.ts";
Expand Down Expand Up @@ -98,8 +98,34 @@ describe("a child that closed its stdin", () => {
}).pipe(Effect.provide(ProcessRunner.layer.pipe(Layer.provideMerge(NodeServices.layer)))),
);

it("is told by the broken pipe's code anywhere under the error", () => {
it.effect("ends with its own exit code when Node already closed its stdin", () =>
Effect.gen(function* () {
const result = yield* runOn(
exitedChild({ code: 3, stdout: "", stdin: "ERR_STREAM_DESTROYED" }),
{ command: "program", args: [], stdin: "input" },
);
assert.strictEqual(result.code, 3);
}),
);

it.live("a write after a real child has exited counts as a closed stdin", () =>
Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const child = yield* spawner.spawn(
ChildProcess.make(process.execPath, ["-e", "process.exit(3)"]),
);
yield* child.exitCode;
const error = yield* Stream.run(Stream.encodeText(Stream.make("late")), child.stdin).pipe(
Effect.flip,
);
assert.isTrue(isClosedStdin(error));
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it("is told by the closed pipe's code anywhere under the error", () => {
assert.isTrue(isClosedStdin(stdinFailure("EPIPE")));
assert.isTrue(isClosedStdin(stdinFailure("ERR_STREAM_DESTROYED")));
assert.isTrue(isClosedStdin(stdinFailure("ERR_STREAM_PREMATURE_CLOSE")));
assert.isTrue(isClosedStdin({ code: "EPIPE" }));
assert.isFalse(isClosedStdin(stdinFailure("EIO")));
assert.isFalse(isClosedStdin(undefined));
Expand Down
14 changes: 12 additions & 2 deletions apps/server/src/fork/processRunnerFork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ export const collectTail = <E>(stream: Stream.Stream<Uint8Array, E>, maxBytes: n
);

/**
* True when `error` (or a cause under it) is EPIPE: the child closed its stdin before the runner
* Node's codes for a write to a child's stdin that is already closed: EPIPE when the child closed
* it first, the other two when Node saw the child exit and closed it itself.
*/
const CLOSED_STDIN_CODES: ReadonlySet<unknown> = new Set([
"EPIPE",
"ERR_STREAM_DESTROYED",
"ERR_STREAM_PREMATURE_CLOSE",
]);

/**
* True when `error` (or a cause under it) says the child's stdin was closed before the runner
* wrote it, e.g. `timeout` exiting 127 at once for a missing program. Not a failure to run it;
* its exit code and output say how it ended.
*/
export function isClosedStdin(error: unknown): boolean {
let current: unknown = error;
for (let depth = 0; depth < 6 && typeof current === "object" && current !== null; depth += 1) {
if ((current as { readonly code?: unknown }).code === "EPIPE") return true;
if (CLOSED_STDIN_CODES.has((current as { readonly code?: unknown }).code)) return true;
const reason = (current as { readonly reason?: unknown }).reason;
current =
typeof reason === "object" && reason !== null && "cause" in reason
Expand Down
7 changes: 3 additions & 4 deletions apps/server/src/golive/forkReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,9 @@ describe("__fork-report settings", () => {
expect(cleared.featuresOn).toEqual(featuresOn);
expect(Object.values(cleared.featuresWhere).flat()).toEqual(featuresOn.map(() => "server"));
}
// Pinned: playtest with a key this build does not know stays on.
expect(settingsReport({ playtest: { ...playtest, laterKey: 1 } }).fork.featuresOn).toEqual([
"playtest",
]);
// A playtest value with a key this build does not know reads as off, as the load does: the key
// may be a newer build's limit, so this build must not run playtest without it.
expect(settingsReport({ playtest: { ...playtest, laterKey: 1 } }).fork.featuresOn).toEqual([]);
});

it("names the model policy by its mode, and reads an invalid one as enforce, as the load does", () => {
Expand Down
11 changes: 6 additions & 5 deletions docs/fork/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ In the app: **Settings → Fork**, section Playtest: the switch (it stays off un
set), the steps as JSON under **Edit steps** (checked as a save is), and the limits under Advanced.

Only the person can change it; agents cannot. A save that is on without all four steps, repeats a
push step's name (or names one `claim`, `renew` or `release`), or names a program by anything but
its full path on the server's OS is refused. A hand-edited
value that is not valid reads as off (with a warning in the server log), and the next save of any
setting writes the default in its place; fields a newer build added are dropped the same way (as for
`waitChecks`). Other fields: how often a claim is renewed (`renewMinutes`), when an idle
push step's name (or names one `claim`, `renew` or `release`), names a program by anything but its
full path on the server's OS, or has a field this build does not know is refused. A hand-edited
value that is not valid, or has a field this build does not know (a newer build's limit, a typo),
reads as off (with a warning in the server log), and the next save of any setting writes the default
in its place. So after moving back to an older build, copy the playtest value first: the older
build's next save replaces a newer build's value. Other fields: how often a claim is renewed (`renewMinutes`), when an idle
session ends (`idleMinutes`) and the longest session (`maxHours`).

```json
Expand Down
3 changes: 2 additions & 1 deletion fork-ci/actions/ci-demand/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ Two choices to keep in mind when comparing before and after:
## General vs project

General: the command, its counting rules and its cache. Project: only the repository (an argument, or `ciDemand.repo`
in the project's own config file) and where the caller keeps the cache.
in the project's own config file) and where the caller keeps the cache. The examples here, as in
[fleet-route](../fleet-route/README.md), call that file `.github/fleet.json`; the name is the project's choice.
18 changes: 9 additions & 9 deletions fork-ci/actions/docs-scope/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ jobs:
base: ${{ steps.green.outputs.sha }} # empty: a full run
- if: steps.scope.outputs.docs_only != 'true'
run: ./gradlew build
- if: fromJSON(steps.scope.outputs.jobs).engine != 'false'
run: ./gradlew :engine:test
- if: fromJSON(steps.scope.outputs.jobs).core != 'false'
run: ./gradlew :core:test
```

Always test `!= 'true'` and `!= 'false'`, never `== 'false'` or `== 'true'`: a missing or empty output then means
"run". `jobs` is `{}` when the change or the config is unknown, so every job reads as "run".

Run it as a step of the jobs it gates, as above. If it runs in a job of its own that others `need`, a failure of that
job skips them, and GitHub counts a skipped required job as passing: gate them with
`if: ${{ !cancelled() && (needs.scope.result != 'success' || fromJSON(needs.scope.outputs.jobs).engine != 'false') }}`.
`if: ${{ !cancelled() && (needs.scope.result != 'success' || fromJSON(needs.scope.outputs.jobs).core != 'false') }}`.

### Outputs

Expand All @@ -54,8 +54,8 @@ job skips them, and GitHub counts a skipped required job as passing: gate them w
| `jobs` | JSON `{"<job>": "true" \| "false"}`; `{}` when unknown |
| `reason` | one line: `docs-only:`, `full run:`, `scoped run:` or `not docs-only:` and why |

The step log also prints one line per job: `job engine: run (engine/A.java matches its paths)` or
`job engine: skip (...)`. Control characters, line separators and bytes that are not UTF-8 in a file name are
The step log also prints one line per job: `job core: run (core/A.java matches its paths)` or
`job core: skip (...)`. Control characters, line separators and bytes that are not UTF-8 in a file name are
printed escaped (`\n`, `\udcff`), so a file name can neither start a `::workflow-command::` line nor add an output.

## What "the change" is
Expand Down Expand Up @@ -93,7 +93,7 @@ the diff to commits a passing push run already tested.
"never_docs": [
{ "glob": "**/src/**", "why": "inside a source set (packed into jars)" },
{ "glob": "**/tests/**", "why": "inside a test folder" },
{ "glob": "tools/CLAIMS.md", "why": "read by the release tool" }
{ "glob": "tools/RELEASE-NOTES.md", "why": "read by the release tool" }
],
"never_docs_from": [
{
Expand All @@ -107,13 +107,13 @@ the diff to commits a passing push run already tested.
"docs_only_events": ["pull_request"],
"no_build": [".github/ISSUE_TEMPLATE/**", "tools/notes/**"],
"jobs": {
"engine": {
"paths": ["engine/**", "shared/items/**"],
"core": {
"paths": ["core/**", "shared/common/**"],
"paths_from": [
{
"file": "tools/modules.json",
"list": "modules",
"where": { "kind": "engine-module" },
"where": { "kind": "core-module" },
"field": ["paths", "inputs"],
"label": "id"
}
Expand Down
Loading
Loading