Public: anyone can read this; the crew can change it.

"That could not be sealed." lives in one module, read by the backup destination and the mirror #5630

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/5615-that-could-not-be-sealed-lives-in-one-mo → main 3 commits fork 3 threads · 3 unresolved

  • Merged. mason/5615-that-could-not-be-sealed-lives-in-one-mo was merged into main as 3f29c8c.

Review

Sign in to review this change.
5 files changed +37 −2
src/actions/destination.ts +2 −1
@@ -18,6 +18,7 @@ import { s3FromEnv, type S3Target } from "../snapshot/store.ts";
1818 import { snapshotsOf } from "../snapshot/service.ts";
1919 import type { User } from "../core/users.ts";
2020 import { err, ok, type Result } from "../kernel/result.ts";
21 import { NOT_SEALED } from "../kernel/seal_words.ts";
2122
2223 export interface DestinationInput {
2324 readonly endpoint: string;
@@ -79,7 +80,7 @@ export function saveDestination(
7980 for (const [name, value] of fields) {
8081 if (value === "") continue;
8182 const set = putSecret(app, actor, "forge", "", name, value);
82 if (!set.ok) return err("That could not be sealed.");
83 if (!set.ok) return err(NOT_SEALED);
8384 }
8485 snapshotsOf(app)?.forget();
8586 const have = sealedSet(app.db);
src/actions/mirror.ts +2 −1
@@ -17,6 +17,7 @@ import {
1717 import { snapshotsOf } from "../snapshot/service.ts";
1818 import type { User } from "../core/users.ts";
1919 import { err, ok, type Result } from "../kernel/result.ts";
20 import { NOT_SEALED } from "../kernel/seal_words.ts";
2021
2122 const isAdmin = (actor: User | undefined): boolean => actor?.isAdmin === true;
2223
@@ -47,7 +48,7 @@ export function saveMirror(
4748 for (const [name, value] of fields) {
4849 if (value === "") continue;
4950 if (!putSecret(app, actor, "forge", "", name, value).ok)
50 return err("That could not be sealed.");
51 return err(NOT_SEALED);
5152 }
5253 // A new target is not judged by the old one's last pass.
5354 const svc = snapshotsOf(app);
src/kernel/seal_words.ts added +6
@@ -0,0 +1,6 @@
1 /**
2 * What an admin is told when a credential they gave cannot be sealed as a
3 * forge-level secret. The backup destination and the off-box mirror both
4 * say it, on the web and in the terminal, so it is written once here.
5 */
6 export const NOT_SEALED = "That could not be sealed.";
test/seal-words.test.ts added +26
@@ -0,0 +1,26 @@
1 /**
2 * "That could not be sealed." is said from `src/kernel/seal_words.ts` and
3 * nowhere else: the destination and the mirror import it, and a copy typed
4 * back into either fails here.
5 */
6 import { describe, expect, test } from "bun:test";
7 import { readFileSync } from "node:fs";
8 import { join } from "node:path";
9 import { NOT_SEALED } from "../src/kernel/seal_words.ts";
10
11 const root = join(import.meta.dir, "..");
12 const read = (path: string) => readFileSync(join(root, path), "utf8");
13
14 describe("the words for a credential that could not be sealed", () => {
15 test("the module says them as they were said", () => {
16 expect(NOT_SEALED).toBe("That could not be sealed.");
17 });
18
19 for (const path of ["src/actions/destination.ts", "src/actions/mirror.ts"]) {
20 test(`${path} imports them and types no copy`, () => {

This reads source text. A behavioural check that saveDestination and saveMirror return NOT_SEALED when putSecret fails would be stronger and survive a refactor.

21 const text = read(path);
22 expect(text).not.toContain(NOT_SEALED);

This asserts on file text, which breaks on a harmless reformat of the import. Assert on the returned error from a failing putSecret instead.

23 expect(text).toContain('from "../kernel/seal_words.ts"');
24 });
25 }
26 });
test/shards.test.ts +1
@@ -515,6 +515,7 @@ describe("parseShardSpec", () => {
515515 expect(parseShardSpec("1/3")).toEqual({ ok: true, index: 1, total: 3 });
516516 expect(parseShardSpec("3/3")).toEqual({ ok: true, index: 3, total: 3 });
517517 expect(parseShardSpec(" 2/4 ")).toEqual({ ok: true, index: 2, total: 4 });
518 // The gate passed a thousand files; a slice of the last one still parses.
518519 expect(parseShardSpec("1000/1000")).toEqual({ ok: true, index: 1000, total: 1000 });
519520 for (const bad of ["0/3", "1/0", "4/3", "1", "1-3", "a/b", "1/3/5"])
520521 expect(parseShardSpec(bad).ok).toBe(false);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs