mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
Add logicsrc teams tui, a browser for team vaults (#146)
Teams on the left, their vaults in the middle, and the selected vault's
detail on the right across three tabs: secret names, who can decrypt,
and the audit trail.
It never handles plaintext, and that is the point rather than a
limitation. The server only ever holds ciphertext and this keeps it that
way: no decryption key is fetched, none is unwrapped, and there is no
keybinding that would. The secrets tab says so on screen and points at
`logicsrc teams pull`, because otherwise the first thing anyone does is
hunt for a reveal key. A value that can appear on screen can appear in a
screen share, a scrollback buffer or a recording; names are what you
need to navigate, values are what you rarely need to look at.
Names, fingerprints and versions are enough to answer the questions you
actually open this for: does the vault exist, has the rotation landed,
and who can still read it.
Notes on the shape:
- Vaults and detail load lazily, because each is a round trip. The
three detail calls are settled independently, so a member without
decryption access still sees the vault's shape and a missing audit
endpoint does not blank the secrets list.
- Changing team resets the vault selection. The old index means
nothing in a different team's list, and keeping it silently selects
an unrelated vault.
- The secrets table shows a date rather than a timestamp. Three fixed
columns plus a name that can run to thirty characters leaves no room,
and a truncated clock looks like data while telling you nothing.
- The audit table gives its widest floor to the action, not the actor:
an email truncates to something recognisable, where "secrets…" could
be put, get or delete.
The view is split from the loader so it renders headlessly without an
authenticated client or a terminal. 17 tests cover that, including one
asserting no ciphertext reaches the screen; 226 pass across the CLI.
Claude-Session: https://claude.ai/code/session_017Df2FNu5DhinMV2soRz3cy
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7f9e493929
commit
ca21348fcd
7 changed files with 688 additions and 0 deletions
175
packages/cli/src/vault-tui.test.ts
Normal file
175
packages/cli/src/vault-tui.test.ts
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { renderToText } from "@profullstack/hqtui/testing";
|
||||
import type { RemoteTeam, RemoteVault } from "@logicsrc/plugin-credential-sharing";
|
||||
import {
|
||||
createVaultState, currentVault, moveSelection, nextPane, nextTab, splitVault, view,
|
||||
type VaultSnapshot, type VaultTuiState,
|
||||
} from "./vault-tui.js";
|
||||
|
||||
const TEAMS: RemoteTeam[] = [
|
||||
{ id: "t1", slug: "profullstack", name: "Profullstack" },
|
||||
{ id: "t2", slug: "coinpay", name: "CoinPay" },
|
||||
];
|
||||
|
||||
const VAULTS: RemoteVault[] = [
|
||||
{ id: "v1", name: "crawlproof--prod", hasAccess: true, secretCount: 12 },
|
||||
{ id: "v2", name: "crawlproof--staging", hasAccess: false, secretCount: 9 },
|
||||
{ id: "v3", name: "legacy", hasAccess: true, secretCount: 1 },
|
||||
];
|
||||
|
||||
function snapshot(): VaultSnapshot {
|
||||
return {
|
||||
teams: TEAMS,
|
||||
vaults: { profullstack: VAULTS, coinpay: [] },
|
||||
details: {
|
||||
v1: {
|
||||
secrets: [
|
||||
{ name: "DATABASE_URL", nonce: "n", ciphertext: "c", fingerprint: "abcdef0123456789", version: 3, updatedAt: "2026-09-08T12:00:00.000Z" },
|
||||
{ name: "STRIPE_SECRET_KEY", nonce: "n", ciphertext: "c", fingerprint: "9876543210fedcba", version: 1, updatedAt: "2026-09-01T09:30:00.000Z" },
|
||||
],
|
||||
grants: [
|
||||
{ email: "anthony@profullstack.com", publicKey: "pk", status: "active", hasPublicKey: true, hasAccess: true },
|
||||
{ email: "new@profullstack.com", publicKey: null, status: "invited", hasPublicKey: false, hasAccess: false },
|
||||
],
|
||||
audit: [{ createdAt: "2026-09-08T12:00:00.000Z", actorEmail: "anthony@profullstack.com", action: "secrets.put" }],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const state = (mutate: (s: VaultTuiState) => void = () => {}): VaultTuiState => {
|
||||
const s = createVaultState(snapshot(), "anthony@profullstack.com");
|
||||
mutate(s);
|
||||
return s;
|
||||
};
|
||||
|
||||
const frame = (s: VaultTuiState, width = 120, height = 26): string =>
|
||||
renderToText((args) => view(args as never, s), { width, height });
|
||||
|
||||
describe("vault name parsing", () => {
|
||||
it("splits project and environment", () => {
|
||||
expect(splitVault("crawlproof--prod")).toEqual({ project: "crawlproof", env: "prod" });
|
||||
});
|
||||
|
||||
it("keeps a name with no separator whole rather than inventing an env", () => {
|
||||
expect(splitVault("legacy")).toEqual({ project: "legacy", env: "—" });
|
||||
});
|
||||
|
||||
it("splits on the last separator, so a project containing one survives", () => {
|
||||
expect(splitVault("a--b--prod")).toEqual({ project: "a--b", env: "prod" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("rendering", () => {
|
||||
it("draws teams, vaults and detail", () => {
|
||||
const out = frame(state());
|
||||
expect(out).toMatch(/Teams \(2\)/);
|
||||
expect(out).toMatch(/profullstack/);
|
||||
expect(out).toMatch(/crawlproof/);
|
||||
expect(out).toMatch(/prod/);
|
||||
});
|
||||
|
||||
it("shows who is signed in, because access depends on it", () => {
|
||||
expect(frame(state())).toMatch(/anthony@profullstack\.com/);
|
||||
expect(frame(state((s) => { s.identity = ""; }))).toMatch(/not signed in/);
|
||||
});
|
||||
|
||||
it("shows secret names and fingerprints but never a value", () => {
|
||||
const out = frame(state((s) => { s.pane = "detail"; }));
|
||||
expect(out).toMatch(/DATABASE_URL/);
|
||||
expect(out).toMatch(/STRIPE_SECRET_KEY/);
|
||||
// The ciphertext and nonce are in the fixture; neither may reach the screen.
|
||||
expect(out).not.toMatch(/ciphertext/);
|
||||
expect(out.includes("\nc\n")).toBe(false);
|
||||
});
|
||||
|
||||
it("says values stay encrypted, so nobody hunts for a reveal key", () => {
|
||||
const out = frame(state((s) => { s.pane = "detail"; }));
|
||||
expect(out).toMatch(/Values stay encrypted/);
|
||||
expect(out).toMatch(/teams pull/);
|
||||
});
|
||||
|
||||
it("shows grants and the audit trail on their own tabs", () => {
|
||||
const grants = frame(state((s) => { s.tab = "grants"; }));
|
||||
expect(grants).toMatch(/anthony@profullstack\.com/);
|
||||
expect(grants).toMatch(/invited/);
|
||||
|
||||
// Wider than the default here: the assertion is about the action reaching
|
||||
// the screen intact, and at 120 columns the detail pane truncates it.
|
||||
const audit = frame(state((s) => { s.tab = "audit"; }), 150);
|
||||
expect(audit).toMatch(/secrets\.put/);
|
||||
expect(audit).toMatch(/2026-09-08 12:00/);
|
||||
});
|
||||
|
||||
it("reports a team with no vaults rather than drawing an empty pane", () => {
|
||||
const out = frame(state((s) => { s.team = 1; }));
|
||||
expect(out).toMatch(/No vaults in this team/);
|
||||
expect(out).toMatch(/teams push coinpay/);
|
||||
});
|
||||
|
||||
it("handles having no teams at all", () => {
|
||||
const out = frame(state((s) => { s.snapshot.teams = []; }));
|
||||
expect(out).toMatch(/No teams/);
|
||||
});
|
||||
|
||||
it("surfaces a detail error instead of an empty list", () => {
|
||||
const out = frame(state((s) => {
|
||||
s.snapshot.details.v1 = { secrets: [], grants: [], audit: [], error: "secrets: 403 forbidden" };
|
||||
s.pane = "detail";
|
||||
}));
|
||||
expect(out).toMatch(/403 forbidden/);
|
||||
});
|
||||
|
||||
it("does not overflow a narrow terminal", () => {
|
||||
const out = frame(state(), 70, 20);
|
||||
expect(out.split("\n").every((line) => line.length <= 70)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("navigation", () => {
|
||||
it("cycles panes both ways", () => {
|
||||
const s = state();
|
||||
nextPane(s, 1);
|
||||
expect(s.pane).toBe("vaults");
|
||||
nextPane(s, -1);
|
||||
expect(s.pane).toBe("teams");
|
||||
nextPane(s, -1);
|
||||
expect(s.pane).toBe("detail");
|
||||
});
|
||||
|
||||
it("cycles detail tabs and resets the scroll", () => {
|
||||
const s = state((x) => { x.detailOffset = 5; });
|
||||
nextTab(s, 1);
|
||||
expect(s.tab).toBe("grants");
|
||||
expect(s.detailOffset).toBe(0);
|
||||
});
|
||||
|
||||
it("clamps the selection to the list", () => {
|
||||
const s = state((x) => { x.pane = "vaults"; });
|
||||
moveSelection(s, -5);
|
||||
expect(s.vault).toBe(0);
|
||||
moveSelection(s, 99);
|
||||
expect(s.vault).toBe(2);
|
||||
expect(currentVault(s)?.name).toBe("legacy");
|
||||
});
|
||||
|
||||
it("resets the vault selection when the team changes", () => {
|
||||
// The old index means nothing in a different team's list, so keeping it
|
||||
// would silently select an unrelated vault.
|
||||
const s = state((x) => { x.pane = "vaults"; });
|
||||
moveSelection(s, 2);
|
||||
expect(s.vault).toBe(2);
|
||||
s.pane = "teams";
|
||||
moveSelection(s, 1);
|
||||
expect(s.team).toBe(1);
|
||||
expect(s.vault).toBe(0);
|
||||
});
|
||||
|
||||
it("scrolls the detail pane when it has focus", () => {
|
||||
const s = state((x) => { x.pane = "detail"; });
|
||||
moveSelection(s, 3);
|
||||
expect(s.detailOffset).toBe(3);
|
||||
moveSelection(s, -99);
|
||||
expect(s.detailOffset).toBe(0);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue