Merge branch 't3/implement-auth-deploy'

Integrate auth, config, watcher and terminal wiring in buildApp: auth guards every API route by default, notebook watcher events feed the /api/events hub, the terminal runs in the configured workspace, and SHELLBOOK_DATA_DIR is the single data directory variable. The systemd unit uses KillMode=process so tmux sessions survive service restarts.
This commit is contained in:
Florian Schmidt
2026-11-16 00:11:06 +01:00
24 changed files with 1232 additions and 21 deletions
+5 -5
View File
@@ -105,7 +105,7 @@ async function sshFixture() {
describe("workspace", () => {
it("reads nested notebooks, lists them, hashes versions, rejects stale concurrent saves", async () => {
const app = await buildApp({ config: await fixture() }); cleanup.push(() => app.close());
const app = await buildApp({ config: await fixture(), auth: false }); cleanup.push(() => app.close());
const url = "/api/notebooks/nested%2Ftest.md";
const res = await app.inject(url);
expect(res.statusCode).toBe(200);
@@ -117,7 +117,7 @@ describe("workspace", () => {
expect((await app.inject(url)).json().version).not.toBe(payload.baseVersion);
});
it("validates inventory and applies defaults", async () => {
const config = await fixture(); const app = await buildApp({ config }); cleanup.push(() => app.close());
const config = await fixture(); const app = await buildApp({ config, auth: false }); cleanup.push(() => app.close());
expect((await app.inject("/api/hosts")).json().hosts[0]).toEqual({ name: "test", address: "localhost", user: "admin", port: 22, tags: [] });
await writeFile(path.join(config.workspaceDir, "hosts.yaml"), "- name: bad\n address: localhost\n");
expect((await app.inject("/api/hosts")).statusCode).toBe(400);
@@ -128,7 +128,7 @@ describe("workspace", () => {
it("rejects symlink notebooks and non-md paths", async () => {
const config = await fixture();
await symlink(path.join(config.workspaceDir, "notebooks", "nested"), path.join(config.workspaceDir, "notebooks", "link"), "junction");
const app = await buildApp({ config }); cleanup.push(() => app.close());
const app = await buildApp({ config, auth: false }); cleanup.push(() => app.close());
expect((await app.inject("/api/notebooks/link%2Ftest.md")).statusCode).toBe(400);
expect((await app.inject("/api/notebooks/hosts.yaml")).statusCode).toBe(400);
});
@@ -194,7 +194,7 @@ describe("SSH with a deterministic in-process server", () => {
const req = request(); req.acceptHostKey = fp;
await executeRun({ config, hub, runId: first, request: req, step: step(), rendered: r, host, env: {} });
expect(events.at(-1)).toMatchObject({ exitCode: 0, artifacts: ["out.txt"] });
const app = await buildApp({ config }); cleanup.push(() => app.close());
const app = await buildApp({ config, auth: false }); cleanup.push(() => app.close());
const download = await app.inject(`/api/runs/${first}/artifacts/out.txt`);
expect(download.statusCode).toBe(200); expect(download.body).toBe("artifact bytes");
expect((await app.inject(`/api/runs/${first}/artifacts/undeclared.txt`)).statusCode).toBe(404);
@@ -211,7 +211,7 @@ describe("pipeline helpers", () => {
await writeFile(path.join(config.workspaceDir, "hosts.yaml"), JSON.stringify([host]));
vi.mocked(parseNotebook).mockReturnValueOnce({ title: "Test", params: [], blocks: [{ type: "step", step: step() }], diagnostics: [] });
const hub = new EventsHub();
const app = await buildApp({ config, events: hub }); cleanup.push(() => app.close());
const app = await buildApp({ config, events: hub, auth: false }); cleanup.push(() => app.close());
await app.ready();
const socket = await app.injectWS("/api/events"); cleanup.push(async () => socket.close());
const events: ServerEvent[] = [];