feat: chained notebooks with when sections and host blocks (#11)
A notebook can include another one and continue with what it produced:
- core: parse :::when{param=a,b}, ::use{notebook= as= with=} and
::host{name= address= user= port= capture=}; composeNotebook namespaces
an included notebook's params, steps, captures and templates by alias
(cycles, missing files, depth > 4 and child errors are reported on the
use line). Defaults may reference captures and builtins
({{shellbook.public_key}}); required params and secrets gate only steps
of their own scope; secretEnv passes a scope's secrets under local names.
- protocol: NotebookResponse gains includes and builtins.
- server: compose includes on load, inject builtins (client values are
ignored), refuse steps in inactive when sections.
- web: render when/use/host blocks, group included params in the form,
add a created machine to Hosts and capture its name, reload when an
included notebook changes, run all checks only for active steps,
authoring snippets for when, use and host.
This commit is contained in:
@@ -13,7 +13,9 @@ import { SerialQueue, safeRelative } from "../src/workspace";
|
||||
import { connect, exec, fingerprint, HostKeyError, localExec, scriptInput } from "../src/ssh";
|
||||
import { executeRun, EventsHub, prepareRun, redactor } from "../src/runs";
|
||||
|
||||
vi.mock("@shellbook/core", () => ({
|
||||
vi.mock("@shellbook/core", async importOriginal => ({
|
||||
// Composition helpers stay real; parsing and rendering are stubbed per test.
|
||||
...pick(await importOriginal<typeof import("@shellbook/core")>(), "composeNotebook", "notebookIncludes", "findStep", "blockActive", "isBuiltin"),
|
||||
parseNotebook: vi.fn((source: string) => ({ title: source.split("\n")[0], params: [], blocks: [], diagnostics: [] })),
|
||||
shellQuote: (value: string) => /^[A-Za-z0-9._/@:=+-]+$/.test(value) ? value : "'" + value.replaceAll("'", "'\\''") + "'",
|
||||
resolveParams: vi.fn((_notebook: Notebook, values: Record<string, string>) => ({ values, errors: {} })),
|
||||
@@ -21,6 +23,9 @@ vi.mock("@shellbook/core", () => ({
|
||||
secretEnv: vi.fn(() => ({})),
|
||||
}));
|
||||
|
||||
function pick<T extends object, K extends keyof T>(object: T, ...keys: K[]) {
|
||||
return Object.fromEntries(keys.map(key => [key, object[key]])) as Pick<T, K>;
|
||||
}
|
||||
const cleanup: (() => Promise<unknown>)[] = [];
|
||||
afterEach(async () => { for (const fn of cleanup.splice(0).reverse()) await fn(); vi.clearAllMocks(); });
|
||||
async function fixture() {
|
||||
@@ -175,7 +180,7 @@ describe("pipeline helpers", () => {
|
||||
expect(events.at(-1)).toMatchObject({ type: "run.finished", exitCode: -1 });
|
||||
});
|
||||
it("refuses missing or invalid parameters before execution", () => {
|
||||
const notebook: Notebook = { title: "Test", params: [], blocks: [{ type: "step", step: step() }], diagnostics: [] };
|
||||
const notebook: Notebook = { title: "Test", params: [{ name: "required", type: "string", required: true }], blocks: [{ type: "step", step: step() }], diagnostics: [] };
|
||||
vi.mocked(resolveParams).mockReturnValueOnce({ values: {}, errors: { required: "missing" } });
|
||||
expect(() => prepareRun(notebook, request(), [])).toThrow("Parameters are missing or invalid");
|
||||
vi.mocked(renderStep).mockReturnValueOnce({ ...rendered(), missing: ["required"] });
|
||||
|
||||
Reference in New Issue
Block a user