mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 19:27:38 +01:00
Track 0 of docs/master-plan-2026-10.md: stop the leak and the routing lies,
app only, nothing on the box changes.
Stop the leak
- A request on a shared project from a Builder, a client or a viewer is
filed as a suggestion in the owner's tenant (source `client` or the new
`member`), announced like a visitor's note, and waits for the owner's
tap. Only the owner's own word starts a build on the owner's builder
(ask-in-loki.ts, implement.ts, pass-holder.ts). Until now a Builder's
ask built at once on the owner's subscription and a client's built on
a monthly allowance; both spent one person's engine on another's word.
- The per-site allowance is retired: config/client-allowance.ts, the
members PATCH, the People-panel picker, the dossier count, the invite
copy. The `monthly_changes` columns stay in the schema unread (a DROP
aborts the deploy; dropped by hand later). `on_allowance` is kept and
read as `previewFirst`: a change built for the person who asked still
opens as a draft and goes live on their "Make it live".
- The owner pass is the owner's alone; everyone with a seat carries a
member pass. The 40-builds-a-day cap is keyed by the owner, not the
project: a guard on one engine, never a price.
Routing honesty
- inject-core requests only what was chosen (a lock, a named builder, a
stored preference) and lets the decision apply the floor, so a fresh
account with Fleet Runner connected runs there instead of a 403
(execution-access.ts requestedDispatchChannel).
- Kickoff writes a path under the cloud builder's root only for accounts
the cloud serves; for anyone else the path stays empty so the project
is not locked to a builder they do not have.
- "Hosted runner" is offered, accepted and dispatched only for the one
account it serves (lib/hosted-runner/serves.ts).
Records: CHANGELOG entry {#seat-suggests}, ROADMAP milestone ticked,
CLAUDE.md and feedback-widget.md say what a seat's ask is now. Tests:
client-seat rewritten, execution-access extended, the pinned shapes in
client-seat-browser, seat-on-site-and-tracking, feedback-trust,
project-capabilities and owner-note-builds updated.
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
Co-authored-by: Claude <noreply@anthropic.com>
195 lines
7.2 KiB
TypeScript
195 lines
7.2 KiB
TypeScript
/**
|
|
* The project permission boundary, pinned.
|
|
*
|
|
* Priority 5 of the 2026-09-17 review asks for the journey to be proved with an
|
|
* editor and a reporter account. The live two-account walk still needs two real
|
|
* sign-ins; this is the half that does NOT — the rule itself, which until now
|
|
* lived inside a DATABASE_URL-bound query and so had no test at all. The only
|
|
* way to discover that a viewer could edit was to sign in as one and look.
|
|
*
|
|
* These are the claims a permission bug would have to break.
|
|
*/
|
|
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import {
|
|
capabilitiesForRole,
|
|
OWNER_CAPABILITIES,
|
|
ROLE_LABELS,
|
|
askPath,
|
|
askReply,
|
|
roleGuide,
|
|
sharedProjectLine,
|
|
type ProjectCapabilities,
|
|
} from "@/lib/project-capabilities";
|
|
import { PROJECT_ROLE_VALUES } from "@/db/schema/project-memberships";
|
|
|
|
let passed = 0;
|
|
const check = (label: string, fn: () => void) => {
|
|
fn();
|
|
passed += 1;
|
|
console.log(` ✓ ${label}`);
|
|
};
|
|
|
|
check("the owner may do everything, including manage members", () => {
|
|
const owner = capabilitiesForRole("owner");
|
|
assert.equal(owner.canEdit, true);
|
|
assert.equal(owner.canManageMembers, true);
|
|
assert.deepEqual(owner, OWNER_CAPABILITIES);
|
|
});
|
|
|
|
check("an editor works the project but never changes who can reach it", () => {
|
|
const editor = capabilitiesForRole("editor");
|
|
assert.equal(editor.canEdit, true, "an editor is there to do the work");
|
|
assert.equal(
|
|
editor.canManageMembers,
|
|
false,
|
|
"membership is the owner's decision about their own tenant",
|
|
);
|
|
});
|
|
|
|
// A reporter is given `viewer` on the project they filed against: they can watch
|
|
// the fix, they cannot spend the owner's runner on another one.
|
|
check("a viewer reads and nothing more", () => {
|
|
const viewer = capabilitiesForRole("viewer");
|
|
assert.equal(viewer.canEdit, false, "a reporter must not be able to dispatch work");
|
|
assert.equal(viewer.canManageMembers, false);
|
|
});
|
|
|
|
// The client is who the project is for. They see everything a viewer sees and
|
|
// are named as the client on the roster; they do not spend the owner's runner.
|
|
check("a client follows and is named, but does not dispatch", () => {
|
|
const client = capabilitiesForRole("client");
|
|
assert.equal(client.canEdit, false, "the client is not the builder");
|
|
assert.equal(client.canManageMembers, false);
|
|
assert.equal(ROLE_LABELS.client.label, "Client");
|
|
});
|
|
|
|
check("every role has a label and a help line the roster can show", () => {
|
|
for (const role of ["owner", ...PROJECT_ROLE_VALUES] as const) {
|
|
assert.ok(ROLE_LABELS[role].label.length > 1, `${role} needs a label`);
|
|
assert.ok(ROLE_LABELS[role].help.startsWith(ROLE_LABELS[role].label), `${role} help names it`);
|
|
}
|
|
assert.equal(
|
|
ROLE_LABELS.editor.label,
|
|
"Builder",
|
|
"the stored value stays editor; the word is Builder",
|
|
);
|
|
});
|
|
|
|
check("NOBODY but the owner can manage members", () => {
|
|
for (const role of PROJECT_ROLE_VALUES) {
|
|
assert.equal(
|
|
capabilitiesForRole(role).canManageMembers,
|
|
false,
|
|
`${role} must not be able to change the member list`,
|
|
);
|
|
}
|
|
});
|
|
|
|
check("every declared role has a decided answer — none falls through", () => {
|
|
for (const role of PROJECT_ROLE_VALUES) {
|
|
const caps: ProjectCapabilities | undefined = capabilitiesForRole(role);
|
|
assert.ok(caps, `${role} has no capabilities entry`);
|
|
assert.equal(typeof caps.canEdit, "boolean", `${role}.canEdit must be decided`);
|
|
assert.equal(
|
|
typeof caps.canManageMembers,
|
|
"boolean",
|
|
`${role}.canManageMembers must be decided`,
|
|
);
|
|
}
|
|
});
|
|
|
|
check("no collaborator role is silently as powerful as the owner", () => {
|
|
for (const role of PROJECT_ROLE_VALUES) {
|
|
assert.notDeepEqual(
|
|
capabilitiesForRole(role),
|
|
OWNER_CAPABILITIES,
|
|
`${role} was granted the full owner capability set`,
|
|
);
|
|
}
|
|
});
|
|
|
|
// The manual a non-technical person reads before and after joining: every
|
|
// seat is told the owner decides. A Builder used to be told "nothing waits
|
|
// for them" — true only because the build ran on the owner's subscription
|
|
// (gone 2026-10-20: whoever asks pays, in their own builder).
|
|
check("the role guide says what happens to what they ask for", () => {
|
|
const names = { site: "petvity.orangecat.ch", owner: "George" };
|
|
const builder = roleGuide("editor", names);
|
|
assert.equal(builder.steps.length, 2);
|
|
assert.match(builder.steps[0], /petvity\.orangecat\.ch/);
|
|
for (const role of ["editor", "viewer", "client"] as const) {
|
|
const guide = roleGuide(role, names);
|
|
assert.match(guide.then, /George sees it first/);
|
|
assert.doesNotMatch(guide.then, /Loki builds/);
|
|
}
|
|
assert.match(roleGuide("viewer", { site: null, owner: "George" }).steps[0], /the site/);
|
|
});
|
|
|
|
// Walking the loop as Manu (2026-10-18): Loki's own "Ask Loki" told a Builder
|
|
// to edit HTML and install the desktop app. There are two doors now — the
|
|
// project's page in Loki and the site — and both say what happens next.
|
|
check("an ask from Loki is answered with what happens to it", () => {
|
|
assert.match(
|
|
roleGuide("editor", { site: "petvity.orangecat.ch", owner: "George" }).steps[0],
|
|
/page in Loki/,
|
|
);
|
|
const built = askReply("owner", {
|
|
owner: "George",
|
|
site: "petvity.orangecat.ch",
|
|
building: true,
|
|
});
|
|
assert.match(built, /^Loki is building it now/);
|
|
assert.match(built, /petvity\.orangecat\.ch/);
|
|
assert.doesNotMatch(askReply("owner", { owner: "George", site: null, building: true }), /George/);
|
|
assert.equal(
|
|
askReply("owner", {
|
|
owner: "George",
|
|
site: null,
|
|
building: false,
|
|
buildNote: "Saved. You have sent a lot today.",
|
|
}),
|
|
"Saved. You have sent a lot today.",
|
|
"the owner hears why a build did not start, in the build's own words",
|
|
);
|
|
for (const role of ["editor", "viewer", "client"] as const)
|
|
assert.equal(
|
|
askReply(role, { owner: "George", site: null, building: true }),
|
|
"Sent to George. They decide, and you are told when it ships.",
|
|
"a seat is never told it is being built: the owner decides",
|
|
);
|
|
assert.equal(
|
|
askPath("a873c84a-5030-4068-9fbc-683a86a95c58"),
|
|
"/projects/a873c84a-5030-4068-9fbc-683a86a95c58#ask",
|
|
);
|
|
});
|
|
|
|
check("the chat knows where a shared project is changed", () => {
|
|
const line = sharedProjectLine(
|
|
{
|
|
name: "petvity",
|
|
role: "editor",
|
|
ownerName: "George",
|
|
liveUrl: "https://petvity.orangecat.ch",
|
|
},
|
|
"https://loki.orangecat.ch/projects/x#ask",
|
|
);
|
|
assert.match(line, /you are its Builder/);
|
|
assert.match(line, /projects\/x#ask/);
|
|
assert.match(line, /George decides/);
|
|
assert.match(
|
|
sharedProjectLine({ name: "p", role: "viewer", ownerName: null, liveUrl: null }, "u"),
|
|
/its owner decides/,
|
|
);
|
|
const read = (f: string) => readFileSync(f, "utf8");
|
|
assert.match(read("src/lib/agent/sources-fleet.ts"), /projects_shared_with_you/);
|
|
assert.match(read("src/lib/agent/sources.ts"), /sharedProjectFacts\(userId\)/);
|
|
// Today and Control lead with the shared project, not "Add a project" or a download.
|
|
assert.match(read("src/app/(app)/today/page.tsx"), /<SharedProjectsCard/);
|
|
assert.match(read("src/components/control/ControlPanel.tsx"), /onlyShared && \(/);
|
|
assert.match(read("src/components/projects/ProjectWorkspaceHeader.tsx"), /member \? "#ask"/);
|
|
});
|
|
|
|
console.log(`\nproject-capabilities: ${passed} checks passed`);
|