Skip to content
Closed
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ arrives on the update stream, not when the ack lists it as applied.

**Batches abort the remainder.** If op *k* fails, ops 0..*k*-1 stay applied and
ops *k*..*n* are not applied at all. Fix the failing op and resend the whole
batch with the **same** `op_id`s: the prefix comes back in `skipped`, the
batch with the **same** `op_id`s: the prefix comes back with `outcome: "no-op"`, the
remainder applies. Rejected ops consume no `op_id`, so a batch is retryable.

**The four `connect` rejections that used to break this are fixed (#34).**
Expand All @@ -491,8 +491,8 @@ Rejection codes: `malformed_op`, `unknown_op`, `op_deferred`,
`catalog_required`, `invalid_node_payload`, `unknown_widget`,
`uncatalogued_widget_write`, `opaque_widgets`, `widget_out_of_range`,
`input_slot_missing`, `output_slot_missing`, `not_a_subgraph`,
`interior_node_not_found`, `shared_definition_unforked`, and `apply_failed` for
anything unexpected. Match on `code`, never on `message`.
`interior_node_not_found`, `shared_definition_unforked`, `batch_aborted`, and
`apply_failed` for anything unexpected. Match on `code`, never on `message`.

`uncatalogued_widget_write` means a NAME-KEYED widget write named a class the
pinned catalog does not describe. `add_node` and `set_widget` (and `connect`'s
Expand Down
12 changes: 1 addition & 11 deletions test/applier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
type WorkflowJSON,
type WorkflowNode,
} from "../src/index.js";
import { noOpIds, rejectedOutcome } from "./apply-result-helpers.js";
import { canonicalize, loadCatalog, loadLwwVectors, loadSession, sessionFiles } from "./helpers.js";

const catalog = loadCatalog();
Expand All @@ -47,21 +48,10 @@ function envelope(actor: string, baseVersion: number) {
return { op_id: testOpId(), actor, base_version: baseVersion, stamp: [baseVersion, actor] as [number, string] };
}

function rejectedOutcome(result: ReturnType<typeof applyOps>) {
return result.outcomes.find(
(outcome): outcome is Extract<(typeof result.outcomes)[number], { outcome: "rejected" }> =>
outcome.outcome === "rejected" && outcome.reason.code !== "batch_aborted",
);
}

function processedOpIds(result: ReturnType<typeof applyOps>): string[] {
return result.outcomes.filter((outcome) => outcome.outcome !== "rejected").map((outcome) => outcome.op_id);
}

function noOpIds(result: ReturnType<typeof applyOps>): string[] {
return result.outcomes.filter((outcome) => outcome.outcome === "no-op").map((outcome) => outcome.op_id);
}

describe("idempotency (byte-identical re-apply)", () => {
for (const file of sessionFiles()) {
it(`${file}: full stream twice + every op re-applied → byte-identical state`, () => {
Expand Down
50 changes: 50 additions & 0 deletions test/apply-result-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, it } from "vitest";
import type { ApplyResult } from "../src/types.js";
import { noOpIds, rejectedOutcome } from "./apply-result-helpers.js";

describe("ApplyResult helpers", () => {
it("returns the substantive rejection when an aborted outcome precedes it", () => {
const result: ApplyResult = {
outcomes: [
{
op_id: "aborted",
outcome: "rejected",
reason: { code: "batch_aborted", message: "not processed" },
},
{
op_id: "failed",
outcome: "rejected",
reason: { code: "unknown_widget", message: "missing widget" },
},
],
ops_seen: 0,
};

expect(rejectedOutcome(result)).toEqual(result.outcomes[1]);
});

it("returns no substantive rejection for an aborted-only result", () => {
const result: ApplyResult = {
outcomes: [
{
op_id: "aborted",
outcome: "rejected",
reason: { code: "batch_aborted", message: "not processed" },
},
],
ops_seen: 0,
};

expect(rejectedOutcome(result)).toBeUndefined();
});

it("reports successful no-op ids without treating them as rejections", () => {
const result: ApplyResult = {
outcomes: [{ op_id: "duplicate", outcome: "no-op" }],
ops_seen: 1,
};

expect(rejectedOutcome(result)).toBeUndefined();
expect(noOpIds(result)).toEqual(["duplicate"]);
});
});
5 changes: 4 additions & 1 deletion test/apply-result-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { ApplyResult } from "../src/types.js";

export function rejectedOutcome(result: ApplyResult) {
return result.outcomes.find((outcome) => outcome.outcome === "rejected");
return result.outcomes.find(
(outcome): outcome is Extract<ApplyResult["outcomes"][number], { outcome: "rejected" }> =>
outcome.outcome === "rejected" && outcome.reason.code !== "batch_aborted",
);
}

export function rejectedOutcomeWithIndex(result: ApplyResult) {
Expand Down