// The prompt module's shape (novox/hq ADR 0204, ADR 0205): the vendored release is pinned, carries // its licence in the archive, and is loaded with its configuration from the normal slot. import { test } from "node:test"; import assert from "node:assert/strict"; import { existsSync, readFileSync, statSync } from "node:fs"; const at = (p: string) => new URL(`../${p}`, import.meta.url); const m = JSON.parse(readFileSync(at("module.json"), "utf8")); const artifact = (name: string) => m.build.artifacts.find((a: { name: string }) => a.name === name); test("the theme archive is built from the vendored release and carries its licence", () => { assert.deepEqual(artifact("theme"), { name: "theme", kind: "archive", from: "theme" }); assert.match(readFileSync(at("theme/LICENSE"), "utf8"), /Permission is hereby granted, free of charge/); assert.ok(existsSync(at("theme/powerlevel10k.zsh-theme"))); assert.ok(existsSync(at("theme/gitstatus/LICENSE"))); }); test("the configuration archive holds the prompt's configuration and nothing else", () => { assert.deepEqual(artifact("configuration"), { name: "configuration", kind: "archive", from: "config" }); assert.ok(statSync(at("config/p10k.zsh")).size > 0); }); test("both are unpacked under the account's home, owned by the account", () => { const byId = Object.fromEntries(m.resources.map((r: { id: string }) => [r.id, r])); assert.deepEqual(byId.theme, { id: "theme", type: "archive", path: "${machine:account-home}/.local/share/powerlevel10k", owner: "${machine:account}", artifact: "theme" }); assert.deepEqual(byId.configuration, { id: "configuration", type: "archive", path: "${machine:account-home}/.config/powerlevel10k", owner: "${machine:account}", artifact: "configuration" }); }); test("the zsh code in the normal slot sources the theme, then the configuration, and turns on no instant prompt", () => { assert.equal(m.shell.length, 1); const [c] = m.shell; assert.equal(c.for, "zsh"); assert.equal(c.slot, "normal"); const sourced = [...(c.code as string).matchAll(/\|\| source (\S+)/g)].map((x) => x[1]); assert.deepEqual(sourced, ["~/.local/share/powerlevel10k/powerlevel10k.zsh-theme", "~/.config/powerlevel10k/p10k.zsh"]); assert.doesNotMatch(c.code, /instant/); }); test("the README names the upstream, the version and the licence", () => { const readme = readFileSync(at("README.md"), "utf8"); assert.match(readme, /github\.com\/romkatv\/powerlevel10k/); assert.match(readme, /v1\.20\.0/); assert.match(readme, /MIT/); assert.match(m.shell[0].code, /v1\.20\.0/, "the version in the shell code's comment matches"); });