diff --git a/INTERFACE.md b/INTERFACE.md index 9aea618a..8534e463 100644 --- a/INTERFACE.md +++ b/INTERFACE.md @@ -1490,7 +1490,9 @@ built, not entries in this inventory. Adding one is not §18 work; adding a **panel** still is. **Three panels join the inventory under Stage 10, and are marked as such.** -`ExportPanel` (§22.7) is **Stage 10A**; `ProvidersPanel` + `SignInDialog` +`ExportPanel` (§22.7) is **Stage 10A**; `SourcingPanel` (issue #12) reads +declared manufacturing identity from the existing properties route; +`ProvidersPanel` + `SignInDialog` (§23.8) are **Stage 10B**, with the panel's discovery affordance **Stage 10C** (§23.5). They are **not** Stage 4/5 work and do not become so by appearing here. They are listed because a closed list that silently acquires members is not closed, and @@ -4300,6 +4302,15 @@ the header: the header is 44px of the most contested space in the app and alread renders the word "current" twice in two different closed vocabularies (§4.1) — adding a third element there is how that defect happened. +**AMENDED (issue #12).** The inspector tab stays — history, drawings, documents, +and the two-step download live there, and every `data-export-*` selector is +unchanged. The operator session also puts a simple **Export** and **BOM** +control in header chrome next to the pin, so egress is not only a buried tab. +Both still send `WorkspaceState.artifact_ref` verbatim (§22.5). BOM/sourcing +reads only manufacturing fields the part already declares (`process`, +`stock_form`, `blank_size`, `material_spec`); there is no `conform_to` on the +`part.*` surface and no live vendor catalog. + **TIGHTENING.** `ExportPanel` is the only Inspector tab containing a control that writes, so it renders its **subject before its controls**: the pinned ref, its `pin_mode`, and the part, on the first line, above any format button. There is no diff --git a/server/src/hephaestus/http/context.py b/server/src/hephaestus/http/context.py index 0cfa8b04..edf03776 100644 --- a/server/src/hephaestus/http/context.py +++ b/server/src/hephaestus/http/context.py @@ -144,13 +144,13 @@ _STAGE_TABS: Final[frozenset[str]] = frozenset( {"viewport", "script", "timeline", "results", "diff"} ) -#: Six, not five: §22.7's DECISION gives the Inspector an ``export`` tab. The -#: envelope's tab tokens are *the client's own* navigation vocabulary, so this -#: set tracks ``web/src/state/workspace.ts::INSPECTOR_TABS`` — a tab the client -#: can open and this route refuses would be a composer that stops working when -#: the operator changes panel. +#: Tracks ``web/src/state/workspace.ts::INSPECTOR_TABS``. §22.7 added +#: ``export``; issue #12 added ``sourcing`` (BOM from declared manufacturing +#: fields). The envelope's tab tokens are *the client's own* navigation +#: vocabulary — a tab the client can open and this route refuses would be a +#: composer that stops working when the operator changes panel. _INSPECTOR_TABS: Final[frozenset[str]] = frozenset( - {"results", "properties", "provenance", "checks", "dfm", "export"} + {"results", "properties", "provenance", "checks", "dfm", "export", "sourcing"} ) #: The marker a shortened block carries **in its own text**. The model cannot diff --git a/web/e2e/chrome.spec.ts b/web/e2e/chrome.spec.ts new file mode 100644 index 00000000..0a29e7b7 --- /dev/null +++ b/web/e2e/chrome.spec.ts @@ -0,0 +1,83 @@ +// Copyright 2026 The Hephaestus Authors +// SPDX-License-Identifier: Apache-2.0 +// +// Export / BOM chrome bound to the on-screen pin (issue #12). Expected values +// come from the server in the same run. No assertion is on UI copy. + +import { expect, test } from "@playwright/test"; +import { archive } from "./harness/archive"; +import { api, open, route } from "./harness/world"; + +const PART = "tread"; + +interface PropertiesDocument { + readonly properties: Readonly>; + readonly fields: readonly string[]; + readonly source: string; + readonly build_artifact_ref: string | null; +} + +interface BuildDocument { + readonly status: string; + readonly artifact_ref: string; +} + +test("Export and BOM sit in header chrome, not only the inspector", async ({ page }, testInfo) => { + await open(page, route(PART, { tab: "viewport" })); + await expect(page.locator("[data-part-chrome]")).toBeVisible(); + await expect(page.locator("[data-chrome-export]")).toBeVisible(); + await expect(page.locator("[data-chrome-bom]")).toBeVisible(); + // The inspector export tab still exists; chrome is in addition to it. + await expect(page.locator('[data-inspector-tab="export"]')).toBeVisible(); + await expect(page.locator('[data-inspector-tab="sourcing"]')).toBeVisible(); + await archive(page, testInfo, "export-bom-chrome"); +}); + +test("chrome Export is bound to the pin the server named", async ({ page }, testInfo) => { + const build = await api(`/parts/${PART}/build`); + expect(build.artifact_ref).toMatch(/^artifact:build:/); + + await open(page, route(PART, { tab: "viewport" })); + await page.locator("[data-chrome-export]").click(); + await expect(page.locator("[data-panel='export-chrome']")).toBeVisible(); + + await expect( + page.locator("[data-panel='export-chrome'] [data-source='workspace.artifact_ref']"), + ).toHaveAttribute("data-value", build.artifact_ref); + + const formats = await page + .locator("[data-panel='export-chrome'] button[data-export-format]") + .evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-export-format"))); + expect(formats).toEqual(["step", "dxf", "svg", "gltf", "3mf", "stl"]); + + await archive(page, testInfo, "export-chrome-pin"); +}); + +test("chrome BOM shows declared process / stock / material spec from GET properties", async ({ + page, +}, testInfo) => { + const document = await api(`/parts/${PART}/properties`); + const sourcing = ["process", "stock_form", "blank_size", "material_spec"] as const; + const declared = sourcing.filter((field) => field in document.properties); + + await open(page, route(PART, { tab: "viewport" })); + await page.locator("[data-chrome-bom]").click(); + await expect(page.locator("[data-chrome-dialog='sourcing'] [data-panel='sourcing']")).toBeVisible(); + + const fields = await page + .locator("[data-chrome-dialog='sourcing'] [data-field]") + .evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-field"))); + expect([...fields].sort()).toEqual([...declared].sort()); + expect(fields).not.toContain("description"); + expect(fields).not.toContain("finish"); + + for (const field of declared) { + const fact = page.locator( + `[data-chrome-dialog='sourcing'] [data-source="properties.${field}"]`, + ); + await expect(fact).toHaveAttribute("data-value", document.properties[field] ?? ""); + } + + await expect(page.locator("[data-sourcing-catalog='none']").first()).toBeVisible(); + await archive(page, testInfo, "sourcing-chrome"); +}); diff --git a/web/e2e/export.spec.ts b/web/e2e/export.spec.ts index 8190b2e8..7da92741 100644 --- a/web/e2e/export.spec.ts +++ b/web/e2e/export.spec.ts @@ -287,8 +287,15 @@ test("the panel's download is the bytes the route recorded, and carries no token // panel's back legitimately does not appear until its staleness expires. await openExportTab(page); - const before = (await api(`/parts/${PART}/exports`)).exports - .length; + // History is oldest-first (`rowid`). A prior test in this file already + // committed a STEP, so `[data-export-download].last()` is that STEP until + // the panel's own invalidation paints the new row. Matching `.last()` to + // `exports[].outputs.find(.stl)` races those two clocks. + const beforeBlobs = new Set( + (await api(`/parts/${PART}/exports`)).exports + .flatMap((entry) => entry.outputs) + .map((entry) => entry.blob), + ); await page .locator("[data-panel='export'] button[data-export-format='stl']") .click(); @@ -296,26 +303,30 @@ test("the panel's download is the bytes the route recorded, and carries no token // The panel invalidates its own history on a committed export, so the row // arrives without a reload — §22.7's history is live, not a page the operator - // has to go and fetch. - const row = page - .locator("[data-panel='export'] [data-export-download]") - .last(); - await expect(row).toBeVisible({ timeout: 120_000 }); + // has to go and fetch. Wait for the *new* STL the route just recorded, then + // for that blob's Download button — not "any last button". + let output: ExportOutput | undefined; await expect .poll( - async () => - (await api(`/parts/${PART}/exports`)).exports.length, + async () => { + const listed = await api(`/parts/${PART}/exports`); + output = listed.exports + .flatMap((entry) => entry.outputs) + .find( + (entry) => + entry.filename.endsWith(".stl") && !beforeBlobs.has(entry.blob), + ); + return output?.blob ?? null; + }, { timeout: 120_000 }, ) - .toBeGreaterThan(before); - - // What the server recorded, read back off the projection the panel renders. - const listed = await api(`/parts/${PART}/exports`); - const output = listed.exports - .flatMap((entry) => entry.outputs) - .find((entry) => entry.filename.endsWith(".stl")); + .not.toBeNull(); expect(output).toBeDefined(); const recordedBlob = output?.blob ?? ""; + const row = page.locator( + `[data-panel='export'] [data-export-download="${recordedBlob}"]`, + ); + await expect(row).toBeVisible({ timeout: 120_000 }); expect(await row.getAttribute("data-export-download")).toBe(recordedBlob); const requests: string[] = []; diff --git a/web/src/api/types.ts b/web/src/api/types.ts index 300af3ed..c08b3875 100644 --- a/web/src/api/types.ts +++ b/web/src/api/types.ts @@ -327,6 +327,23 @@ export type MetadataField = | "assembly_method" | "joint"; +/** + * Manufacturing identity a BOM/sourcing inspector may render. + * + * Closed subset of `MetadataField`. There is no `conform_to` field on the + * `part.*` surface (`script_contract.md` §5.2); stock is `stock_form` + + * `blank_size`, process is `process`, and the material class the part + * declares is `material_spec`. The client does not invent a tenth name, and + * it does not look any of these up in a vendor catalog. + */ +export const SOURCING_FIELDS = [ + "process", + "stock_form", + "blank_size", + "material_spec", +] as const satisfies readonly MetadataField[]; +export type SourcingField = (typeof SOURCING_FIELDS)[number]; + /** Which read answered a properties projection. Closed (`http/projections.py`). */ export type PropertySource = "build_record" | "script_literals"; diff --git a/web/src/components/Header.module.css b/web/src/components/Header.module.css index 6341c7e9..d3d7c745 100644 --- a/web/src/components/Header.module.css +++ b/web/src/components/Header.module.css @@ -59,6 +59,15 @@ color: var(--ink-muted); } +/* Pin + Export/BOM chrome, left-aligned on the same baseline as the pin. */ +.subject { + display: flex; + align-items: center; + gap: var(--gap-inline); + min-width: 0; + justify-self: start; +} + .right { display: flex; align-items: center; diff --git a/web/src/components/Header.tsx b/web/src/components/Header.tsx index fdc31b24..9480bcd2 100644 --- a/web/src/components/Header.tsx +++ b/web/src/components/Header.tsx @@ -1,7 +1,7 @@ // Copyright 2026 The Hephaestus Authors // SPDX-License-Identifier: Apache-2.0 // -// §4.1's HEADER: `identity → pin → build state → token`. +// §4.1's HEADER: `identity → pin → Export/BOM chrome → build state → token`. // // The two axes §13.1 insists must never blur are split across the shell on // purpose: **the header shows the artifact axis** (pin, build state) and **the @@ -29,6 +29,7 @@ import { useWorkspace } from "../state/react"; import { Chip, formatRef } from "../system"; import { ArtifactPin } from "./ArtifactPin"; import { BuildStateChip } from "./BuildStateChip"; +import { PartChrome } from "./chrome/PartChrome"; import { Fact } from "./Fact"; import styles from "./Header.module.css"; @@ -77,7 +78,10 @@ export function Header({ railToggle }: HeaderProps): React.JSX.Element { )} - +
+ + +
diff --git a/web/src/components/chrome/ExportChrome.tsx b/web/src/components/chrome/ExportChrome.tsx new file mode 100644 index 00000000..8f0b955b --- /dev/null +++ b/web/src/components/chrome/ExportChrome.tsx @@ -0,0 +1,150 @@ +// Copyright 2026 The Hephaestus Authors +// SPDX-License-Identifier: Apache-2.0 +// +// Compact export control for header chrome. Bound to the workspace pin +// (INTERFACE.md §22.5): the request carries `WorkspaceState.artifact_ref` +// verbatim. Formats, blockers, and the submission key are the same ones the +// inspector tab uses — this is not a second exporter. +// +// Drawings, documents, nested-sheet blanks, kerf readout, and history stay +// on the inspector Export tab. Chrome is the simple "take this geometry out" +// path: six formats, as-built, Export. + +import { useState } from "react"; +import { EXPORT_FORMATS, type ExportFormat, type ExportState } from "../../api/exports"; +import { WorkspaceError } from "../../api/client"; +import { copy } from "../../copy"; +import { Button, Panel, PanelBody, PanelHeader, PanelNote, formatRef } from "../../system"; +import { Fact } from "../Fact"; +import { + exportBlocker, + submissionKeyFor, + type Submission, +} from "../inspector/ExportPanel"; +import styles from "./PartChrome.module.css"; + +const CHROME_SUBMISSION = { + subject: "export", + layout: "as_built", + blankWidth: "", + blankHeight: "", + drawingKind: "dimensioned", + sheet: "A4", + docKind: "bom", +} as const; + +export interface ExportChromeProps { + readonly part: string | null; + readonly pinned: string | null; + readonly pinMode: "current" | "pinned"; + readonly onExport: (submission: Submission) => Promise; + readonly onOpenInspector: () => void; +} + +export function ExportChrome(props: ExportChromeProps): React.JSX.Element { + const { part, pinned, pinMode, onExport, onOpenInspector } = props; + const [format, setFormat] = useState("step"); + const [state, setState] = useState("idle"); + const [refusal, setRefusal] = useState(null); + + const submission: Submission = { ...CHROME_SUBMISSION, format, artifactRef: pinned }; + const idempotencyKey = submissionKeyFor(submission); + const blocker = exportBlocker(part, pinned); + const blockerReason = + blocker === "no_part" + ? copy.export.noPart + : blocker === "no_pin" + ? copy.export.noPin + : blocker === "invalid_source" + ? copy.export.refusals.invalid_source + : null; + + const run = (): void => { + setState("exporting"); + setRefusal(null); + void onExport(submission) + .then(() => { + setState("idle"); + }) + .catch((error: unknown) => { + const reason = error instanceof WorkspaceError ? error.reason : ""; + setRefusal( + reason in copy.export.refusals + ? (reason as keyof typeof copy.export.refusals) + : "run_failed", + ); + setState("refused"); + }); + }; + + return ( + + + +
+ {part === null ? ( + {copy.export.noPart} + ) : ( + + )} + {pinned === null ? ( + {copy.export.noPin} + ) : ( + + {formatRef(pinned)} + + )} +
+ {copy.export.subjectNote} + + {blockerReason === null ? null : ( + {blockerReason} + )} + +
+ {EXPORT_FORMATS.map((name) => ( + + ))} +
+ +
+ + +
+ + {refusal === null ? null : ( + {copy.export.refusals[refusal]} + )} +
+
+ ); +} diff --git a/web/src/components/chrome/PartChrome.module.css b/web/src/components/chrome/PartChrome.module.css new file mode 100644 index 00000000..cb3b04c7 --- /dev/null +++ b/web/src/components/chrome/PartChrome.module.css @@ -0,0 +1,40 @@ +/* + * Copyright 2026 The Hephaestus Authors + * SPDX-License-Identifier: Apache-2.0 + * + * LAYOUT ONLY, for the pin-adjacent Export / BOM chrome (INTERFACE.md §3.4). + * Type roles and tokens come from `system/`. + */ + +.chrome { + display: flex; + align-items: center; + gap: var(--gap-inline); + min-width: 0; +} + +.subject { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: var(--gap-inline); + min-width: 0; +} + +.formats { + display: flex; + flex-wrap: wrap; + gap: var(--space-1); + min-width: 0; +} + +.actions { + display: flex; + flex-wrap: wrap; + gap: var(--gap-inline); + align-items: center; +} + +.muted { + color: var(--ink-muted); +} diff --git a/web/src/components/chrome/PartChrome.tsx b/web/src/components/chrome/PartChrome.tsx new file mode 100644 index 00000000..16450eff --- /dev/null +++ b/web/src/components/chrome/PartChrome.tsx @@ -0,0 +1,90 @@ +// Copyright 2026 The Hephaestus Authors +// SPDX-License-Identifier: Apache-2.0 +// +// Part chrome — Export and BOM next to the on-screen pin (issue #12). +// +// §22.7 put export in an inspector tab and said the header gains nothing. +// The operator session (issue #4 / #12) wants a simple control in chrome, +// bound to the thing on screen, not only a buried tab. This cluster sits +// beside the artifact pin. Both buttons still send the workspace pin; they +// do not resolve "current" at click time. +// +// Export opens a compact format+run dialog. BOM opens the sourcing inspector +// (declared `process` / stock / material spec only — no vendor catalog). +// The inspector Export tab stays for history, drawings, and documents. + +import { useState } from "react"; +import { copy } from "../../copy"; +import { workspaceStore } from "../../state/react"; +import { Button, Popover } from "../../system"; +import { ExportChrome } from "./ExportChrome"; +import { useExportActions } from "../inspector/ExportPanel"; +import { SourcingPanel } from "../inspector/SourcingPanel"; +import styles from "./PartChrome.module.css"; + +type ChromeDialog = "export" | "sourcing" | null; + +export function PartChrome(): React.JSX.Element { + const [open, setOpen] = useState(null); + const { part, pinned, pinMode, onExport } = useExportActions(); + + const close = (): void => { + setOpen(null); + }; + const openInspectorExport = (): void => { + workspaceStore.update({ inspector_tab: "export" }); + close(); + }; + + return ( +
+ + + + + + + + + + +
+ ); +} diff --git a/web/src/components/inspector/ExportPanel.tsx b/web/src/components/inspector/ExportPanel.tsx index 192ceeeb..f6ea6ef6 100644 --- a/web/src/components/inspector/ExportPanel.tsx +++ b/web/src/components/inspector/ExportPanel.tsx @@ -110,7 +110,7 @@ export const EXPORT_BLOCKERS = ["no_part", "no_pin", "invalid_source"] as const; export type ExportBlocker = (typeof EXPORT_BLOCKERS)[number]; /** The submission fields, from which the idempotency key is derived (§22.2). */ -interface Submission { +export interface Submission { readonly subject: ExportSubject; readonly format: ExportFormat; readonly layout: ExportLayout; @@ -192,7 +192,7 @@ function refusalKey(error: unknown): keyof typeof copy.export.refusals { */ const SUBMISSION_KEYS = new Map(); -function submissionKeyFor(submission: Submission): string { +export function submissionKeyFor(submission: Submission): string { const id = signature(submission); const existing = SUBMISSION_KEYS.get(id); if (existing !== undefined) return existing; @@ -668,13 +668,21 @@ function HistoryEntry({ } /** - * The panel, bound to the workspace pin. + * The pin-bound export actions. Shared by the inspector tab and the header + * chrome so both send the same `artifact_ref` and mint keys the same way. * * The history is invalidated on a committed export and at no other time: it is * the record of a retention obligation, and this client is the only thing that * can change it from here. */ -export function ExportPanel(): React.JSX.Element { +export function useExportActions(): { + readonly part: string | null; + readonly pinned: string | null; + readonly pinMode: "current" | "pinned"; + readonly history: ExportsDocument | undefined; + readonly onExport: (submission: Submission) => Promise; + readonly onDownload: (output: ExportOutput) => Promise; +} { const part = useWorkspace((s) => s.part); const pinned = useWorkspace((s) => s.artifact_ref); const pinMode = useWorkspace((s) => s.pin_mode); @@ -724,14 +732,20 @@ export function ExportPanel(): React.JSX.Element { [client, part], ); + return { part, pinned, pinMode, history: history.data, onExport, onDownload: downloadExport }; +} + +/** The inspector tab, bound to the workspace pin. */ +export function ExportPanel(): React.JSX.Element { + const { part, pinned, pinMode, history, onExport, onDownload } = useExportActions(); return ( ); } diff --git a/web/src/components/inspector/SourcingPanel.tsx b/web/src/components/inspector/SourcingPanel.tsx new file mode 100644 index 00000000..ba33ac17 --- /dev/null +++ b/web/src/components/inspector/SourcingPanel.tsx @@ -0,0 +1,163 @@ +// Copyright 2026 The Hephaestus Authors +// SPDX-License-Identifier: Apache-2.0 +// +// BOM / sourcing inspector — manufacturing identity the part already declares. +// +// Issue #12: "BOM/sourcing inspector only from manufacturing fields the part +// already declares (`process`, stock, `conform_to`-class). No live vendor +// catalog." There is no `conform_to` field on the `part.*` surface +// (`script_contract.md` §5.2). The closed subset this panel reads is +// `SOURCING_FIELDS`: `process`, `stock_form`, `blank_size`, `material_spec`. +// Values come from `GET /parts/{part}/properties`. Nothing here queries a +// storefront, and no identifier in this file names one. +// +// `data-field` marks declared sourcing fields only, so a set-equality check +// against the projection ∩ `SOURCING_FIELDS` stays exact. An undeclared +// sourcing field is a visible absence (`data-undeclared-field`), not a +// silently missing row. Description, finish, joint, and the other +// `part.*` names stay on the Properties tab — this panel does not restyle +// that one. + +import { SOURCING_FIELDS, type PropertiesDocument, type SourcingField } from "../../api/types"; +import { useProperties } from "../../api/queries"; +import { copy } from "../../copy"; +import { + DataTable, + EmptyState, + Panel, + PanelBody, + PanelHeader, + PanelNote, + PanelSection, + formatRef, + type DataRow, +} from "../../system"; +import { Fact } from "../Fact"; +import { useWorkspace } from "../../state/react"; +import styles from "./panels.module.css"; + +/** One declared sourcing field, attributed to the response path it was read from. */ +function SourcingFact({ field, value }: { readonly field: SourcingField; readonly value: string }) { + switch (field) { + case "process": + return ; + case "stock_form": + return ; + case "blank_size": + return ; + case "material_spec": + return ; + } +} + +export interface SourcingViewProps { + readonly properties: PropertiesDocument; + /** The workspace pin — the artifact on screen, which sourcing is about. */ + readonly pinned: string | null; +} + +export function SourcingView({ properties, pinned }: SourcingViewProps): React.JSX.Element { + const declared = SOURCING_FIELDS.filter((field) => field in properties.properties); + const undeclared = SOURCING_FIELDS.filter((field) => !(field in properties.properties)); + + const rows: readonly DataRow[] = declared.map((field) => ({ + key: field, + label: copy.sourcing.fields[field], + value: , + attrs: { "data-field": field, "data-sourcing-field": field }, + })); + + return ( + + + + + {copy.sourcing.noPin} + ) : ( + + {formatRef(pinned)} + + ), + }, + { + key: "bound", + label: copy.sourcing.boundTo, + value: + properties.build_artifact_ref === null ? ( + {copy.sourcing.unbound} + ) : ( + + ), + }, + ]} + /> + + + {declared.length === 0 ? ( + + ) : ( + + )} + + {undeclared.length === 0 ? null : ( + + ({ + key: field, + label: {copy.sourcing.fields[field]}, + value: {copy.sourcing.undeclared}, + attrs: { "data-undeclared-field": field }, + }))} + /> + {copy.sourcing.undeclaredNote} + + )} + + + , + note: copy.sourcing.source[properties.source], + }, + ]} + /> + {copy.sourcing.catalogNote} + + + + ); +} + +export function SourcingPanel(): React.JSX.Element { + const part = useWorkspace((s) => s.part); + const pinned = useWorkspace((s) => s.artifact_ref); + const properties = useProperties(part); + + if (part === null) { + return ; + } + if (properties.data === undefined) return {copy.absent.loading}; + return ; +} diff --git a/web/src/components/stage/Inspector.tsx b/web/src/components/stage/Inspector.tsx index 0805cf3d..0d6195b7 100644 --- a/web/src/components/stage/Inspector.tsx +++ b/web/src/components/stage/Inspector.tsx @@ -1,22 +1,24 @@ // Copyright 2026 The Hephaestus Authors // SPDX-License-Identifier: Apache-2.0 // -// The INSPECTOR drawer (INTERFACE.md §4.1) — the six tabs of §4.2's panel -// inventory, as a bottom drawer of the Stage rather than a third column. +// The INSPECTOR drawer (INTERFACE.md §4.1) — the closed inspector tabs, as a +// bottom drawer of the Stage rather than a third column. // // §4.1: "INSPECTOR is a bottom drawer of the Stage rather than a third column: // its content is *about the thing in the Stage*, and losing that spatial // relation costs more than the vertical pixels." // // The tab is workspace state (`inspector_tab`, §4.5), so the drawer's selection -// is in the URL and survives a reload like everything else. All six panels of -// the closed inventory are mounted; each is a projection of one read route and -// owns its own named absences (§6.1–§6.4, §4.4). +// is in the URL and survives a reload like everything else. Each panel is a +// projection of one read route and owns its own named absences (§6.1–§6.4, +// §4.4). Sourcing reads the same properties route as Properties, filtered to +// the declared manufacturing-identity fields. // // The sixth is §22.7's `export`, and it is the only one containing a control that -// WRITES. It is here rather than in the header because §4.3's provenance spine -// puts the pin in the header and everything the pin implies in the Inspector, so -// the export tab inherits the pin without a second control. +// WRITES. Issue #12 also puts a compact Export control in header chrome, bound +// to the same pin; this tab keeps history, drawings, and documents. +// +// The seventh is sourcing: BOM from declared manufacturing fields only. // // §4.1(c): the drawer's HEIGHT is not this component's any more — the Stage owns // it as an explicit grid row, and `.content { overflow: auto }` takes the excess. @@ -43,6 +45,7 @@ import { ExportPanel } from "../inspector/ExportPanel"; import { PropertiesPanel } from "../inspector/PropertiesPanel"; import { ProvenancePanel } from "../inspector/ProvenancePanel"; import { ResultsPanel } from "../inspector/ResultsPanel"; +import { SourcingPanel } from "../inspector/SourcingPanel"; import styles from "./Inspector.module.css"; export function Inspector(): React.JSX.Element { @@ -71,6 +74,8 @@ export function Inspector(): React.JSX.Element { ) : tab === "export" ? ( + ) : tab === "sourcing" ? ( + ) : ( { diff --git a/web/src/copy.ts b/web/src/copy.ts index e0d4d69b..a167d727 100644 --- a/web/src/copy.ts +++ b/web/src/copy.ts @@ -60,6 +60,54 @@ export const copy = { "There is no artifact to hold: this part has no build whose artifact the workspace could pin.", }, + /** + * Header chrome next to the pin (issue #12). Export and BOM are simple + * controls bound to the on-screen artifact, not only inspector tabs. + */ + chrome: { + export: "Export", + exportTitle: "Export the pinned artifact", + bom: "BOM", + bomTitle: "Sourcing from this part's declared manufacturing fields", + more: "Drawings, documents, and export history", + }, + + /** + * BOM / sourcing inspector. Only manufacturing identity the part already + * declares — process, stock, material spec. No vendor catalog. + */ + sourcing: { + heading: "Sourcing", + subjectHeading: "This artifact", + pin: "Pinned artifact", + noPin: "No artifact is pinned.", + boundTo: "Evaluated with artifact", + unbound: "No current build; these values were parsed from the script text.", + emptyTitle: "No sourcing fields declared", + empty: + "This part does not declare a process, stock form, blank size, or material spec, so there is nothing to source from.", + undeclared: "not declared", + undeclaredHeading: "Not declared", + undeclaredNote: + "Only manufacturing fields this part declares are used for sourcing. Nothing is looked up from a catalog.", + catalogNote: + "Sourcing is the process, stock, and material spec the part already declares. This workspace does not query a vendor catalog.", + sourceHeading: "Read from", + sourceLabel: "Source", + source: { + build_record: + "the build record — the values as the worker evaluated them, so a computed field reads like a literal one", + script_literals: + "the script's string literals — this part has no current build to read runtime values from, so a computed field cannot be reported", + }, + fields: { + process: "process", + stock_form: "stock form", + blank_size: "blank size", + material_spec: "material spec", + }, + }, + /** §4.5 `pin_mode`, and the §4.1 build-state chip. */ pinMode: { current: "current", @@ -355,6 +403,7 @@ export const copy = { checks: "Checks", dfm: "DFM", export: "Export", + sourcing: "Sourcing", }, pending: "This panel is not part of this build of the workspace yet.", noPartTitle: "No part selected", diff --git a/web/src/state/workspace.ts b/web/src/state/workspace.ts index 5a368c04..c74dc0d4 100644 --- a/web/src/state/workspace.ts +++ b/web/src/state/workspace.ts @@ -48,17 +48,16 @@ export const STAGE_TABS = ["viewport", "script", "timeline", "results", "diff"] export type StageTab = (typeof STAGE_TABS)[number]; /** - * §4.2's panel inventory, plus §22.7's sixth tab. + * §4.2's panel inventory, plus §22.7's `export` tab and the sourcing tab + * issue #12 adds. * - * §22.7's DECISION: "the Inspector gains a sixth tab, `export`. The header gains - * nothing." The Inspector because §4.3's provenance spine puts the *pin* in the - * header and everything the pin *implies* in the Inspector — Results, - * Properties, Provenance, Checks and DFM are all statements about the pinned - * artifact, and an export is another one; it inherits the pin without a second - * control and sits beside the DFM panel whose process pack decides the kerf it - * reports. Not the header, which is 44px of the most contested space in the app - * and already renders the word "current" twice in two different closed - * vocabularies (§4.1). + * §22.7 put export in the Inspector so it inherits the pin. That tab stays: + * history, drawings, documents, and the two-step download live there. Issue + * #12 adds a seventh tab, `sourcing`, for the BOM readout that is only the + * manufacturing fields the part already declares — and it also puts a simple + * Export + BOM control in header chrome next to the pin, so egress is not + * only a buried inspector tab. The chrome still sends + * `WorkspaceState.artifact_ref` verbatim (§22.5). */ export const INSPECTOR_TABS = [ "results", @@ -67,6 +66,7 @@ export const INSPECTOR_TABS = [ "checks", "dfm", "export", + "sourcing", ] as const; export type InspectorTab = (typeof INSPECTOR_TABS)[number]; diff --git a/web/test/chrome.test.tsx b/web/test/chrome.test.tsx new file mode 100644 index 00000000..ff7df272 --- /dev/null +++ b/web/test/chrome.test.tsx @@ -0,0 +1,122 @@ +// Copyright 2026 The Hephaestus Authors +// SPDX-License-Identifier: Apache-2.0 +// +// Pin-bound Export / BOM chrome (issue #12). Assertions are on `data-*` and +// field sets, never on UI copy. + +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { describe, expect, it } from "vitest"; +import { renderToStaticMarkup } from "react-dom/server"; +import type { ReactElement } from "react"; + +import { EXPORT_FORMATS } from "../src/api/exports"; +import { SOURCING_FIELDS } from "../src/api/types"; +import { ExportChrome } from "../src/components/chrome/ExportChrome"; +import { exportBlocker } from "../src/components/inspector/ExportPanel"; +import { INSPECTOR_TABS } from "../src/state/workspace"; + +function render(element: ReactElement): Document { + return new DOMParser().parseFromString( + `${renderToStaticMarkup(element)}`, + "text/html", + ); +} + +function chrome( + overrides: Partial[0]> = {}, +): Document { + return render( + Promise.reject(new Error("not called"))} + onOpenInspector={() => undefined} + {...overrides} + />, + ); +} + +describe("Export chrome — bound to the pin", () => { + it("lives in a panel that is not the inspector export tab", () => { + const dom = chrome(); + expect(dom.querySelector("[data-panel='export-chrome']")).not.toBeNull(); + expect(dom.querySelector("[data-panel='export']")).toBeNull(); + }); + + it("renders its subject before any format button", () => { + const dom = chrome(); + const subject = dom.querySelector("[data-source='workspace.artifact_ref']"); + const firstFormat = dom.querySelector("[data-export-format]"); + expect(subject).not.toBeNull(); + expect(firstFormat).not.toBeNull(); + expect( + (subject?.compareDocumentPosition(firstFormat as Node) ?? 0) & Node.DOCUMENT_POSITION_FOLLOWING, + ).toBeTruthy(); + }); + + it("carries the pin and its mode as server values", () => { + const dom = chrome(); + expect(dom.querySelector("[data-source='workspace.artifact_ref']")?.getAttribute("data-value")).toBe( + "artifact:build:sha256:aaaa", + ); + expect(dom.querySelector("[data-export-pin-mode]")?.getAttribute("data-export-pin-mode")).toBe( + "pinned", + ); + }); + + it("offers exactly the six formats export_part declares", () => { + const buttons = [...chrome().querySelectorAll("button[data-export-format]")].map((node) => + node.getAttribute("data-export-format"), + ); + expect(buttons).toEqual([...EXPORT_FORMATS]); + }); + + it("disables the run control when there is no pin", () => { + const dom = chrome({ pinned: null }); + expect(dom.querySelector("[data-export-run]")?.hasAttribute("disabled")).toBe(true); + expect(dom.querySelector("[data-export-blocked]")?.getAttribute("data-export-blocked")).toBe( + "no_pin", + ); + }); + + it("uses the same blocker the inspector tab uses", () => { + expect(exportBlocker("tread", "artifact:build:sha256:a")).toBeNull(); + expect(exportBlocker("tread", null)).toBe("no_pin"); + expect(exportBlocker("tread", "artifact:export:sha256:a")).toBe("invalid_source"); + }); + + it("offers a door to the inspector tab without replacing it", () => { + expect(chrome().querySelector("[data-chrome-open-inspector='export']")).not.toBeNull(); + expect([...INSPECTOR_TABS]).toContain("export"); + }); +}); + +describe("sourcing field set — declared manufacturing identity only", () => { + it("is a closed subset of part.* and does not invent conform_to", () => { + expect([...SOURCING_FIELDS]).toEqual(["process", "stock_form", "blank_size", "material_spec"]); + expect(SOURCING_FIELDS.includes("process")).toBe(true); + const source = readFileSync(resolve(process.cwd(), "src/api/types.ts"), "utf-8"); + const block = source.slice( + source.indexOf("export const SOURCING_FIELDS"), + source.indexOf("export type SourcingField"), + ); + expect(block).not.toContain("conform_to"); + expect(block).not.toContain("description"); + }); + + it("names no vendor catalog in the sourcing or chrome modules", () => { + const files = [ + "src/components/inspector/SourcingPanel.tsx", + "src/components/chrome/PartChrome.tsx", + "src/components/chrome/ExportChrome.tsx", + "src/copy.ts", + ]; + for (const file of files) { + const text = readFileSync(resolve(process.cwd(), file), "utf-8").toLowerCase(); + expect(text, file).not.toContain("sendcutsend"); + expect(text, file).not.toContain("mcmaster"); + } + }); +}); diff --git a/web/test/exports.test.tsx b/web/test/exports.test.tsx index 76326ecf..105ce0b9 100644 --- a/web/test/exports.test.tsx +++ b/web/test/exports.test.tsx @@ -322,9 +322,10 @@ function panel( } describe("§22.7 — the export panel", () => { - it("is the Inspector's sixth tab", () => { + it("is an Inspector tab, and sourcing sits beside it", () => { expect([...INSPECTOR_TABS]).toContain("export"); - expect(INSPECTOR_TABS).toHaveLength(6); + expect([...INSPECTOR_TABS]).toContain("sourcing"); + expect(INSPECTOR_TABS).toHaveLength(7); }); it("renders its subject above every format button", () => { diff --git a/web/test/inspector.test.tsx b/web/test/inspector.test.tsx index b3483228..9d72b922 100644 --- a/web/test/inspector.test.tsx +++ b/web/test/inspector.test.tsx @@ -45,15 +45,17 @@ import provenanceUnattributedJson from "./fixtures/provenance_unattributed.json" import { visibilityKey } from "../src/state/visibility"; import { ResultsView } from "../src/components/inspector/ResultsPanel"; import { PropertiesView } from "../src/components/inspector/PropertiesPanel"; +import { SourcingView } from "../src/components/inspector/SourcingPanel"; import { ChecksView } from "../src/components/inspector/ChecksPanel"; import { DfmView } from "../src/components/inspector/DfmPanel"; import { ProvenanceView } from "../src/components/inspector/ProvenancePanel"; -import type { - BuildDocument, - ChecksDocument, - DfmDocument, - PropertiesDocument, - ResolvedSelection, +import { + SOURCING_FIELDS, + type BuildDocument, + type ChecksDocument, + type DfmDocument, + type PropertiesDocument, + type ResolvedSelection, } from "../src/api/types"; // The fixtures are JSON, so they arrive structurally typed. Each is asserted @@ -104,6 +106,7 @@ describe("the §1 attribution discipline holds in every panel", () => { const panels: Record = { results: