Skip to content

Commit be507b7

Browse files
committed
fix: show side channel preview tensors
1 parent e168999 commit be507b7

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

vbgui/src/components/sidebar/SideChannelsTab.tsx

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const FAIL_POLICIES: InferenceFailPolicy[] = [
2828
"drop_family", "text_only", "error",
2929
];
3030
const ADAPTERS = ["none", "cpp", "rust", "go", "python"] as const;
31+
type AdapterName = typeof ADAPTERS[number];
3132

3233
export function SideChannelsTab({
3334
sideChannels, availableChannels, selectedTrainChannels, gotchas, onApply,
@@ -42,7 +43,8 @@ export function SideChannelsTab({
4243
standard: "c++20",
4344
});
4445
const [prompt, setPrompt] = useState("int add(int a, int b) { return a + b; }");
45-
const [adapter, setAdapter] = useState<typeof ADAPTERS[number]>("cpp");
46+
const [adapter, setAdapter] = useState<AdapterName>("cpp");
47+
const [tensorPreview, setTensorPreview] = useState<string[]>([]);
4648

4749
useEffect(() => setDraft(sideChannels), [sideChannels]);
4850

@@ -245,6 +247,15 @@ export function SideChannelsTab({
245247
onChange={(e) => setPrompt(e.target.value)}
246248
style={{ width: "100%", minHeight: 54,
247249
fontFamily: "monospace", fontSize: 11 }} />
250+
<button data-testid="side-channel-preview-run"
251+
onClick={() => setTensorPreview(buildTensorPreview({
252+
sideChannels: draft,
253+
prompt,
254+
platformPreview,
255+
adapter,
256+
}))}>
257+
Build preview
258+
</button>
248259
<pre data-testid="side-channel-preview" style={preview}>
249260
{`tokens=${prompt.length}
250261
source=${draft.inference.source}
@@ -253,6 +264,9 @@ adapter=${adapter}
253264
platform=${platformPreview || "unspecified"}
254265
families=${enabledFamilies.join(",") || "none"}`}
255266
</pre>
267+
<pre data-testid="side-channel-preview-tensors" style={preview}>
268+
{tensorPreview.length === 0 ? "not built" : tensorPreview.join("\n")}
269+
</pre>
256270
</section>
257271

258272
<section data-testid="side-channel-probe" style={section}>
@@ -305,6 +319,48 @@ families=${enabledFamilies.join(",") || "none"}`}
305319
}
306320
}
307321

322+
function buildTensorPreview({
323+
sideChannels,
324+
prompt,
325+
platformPreview,
326+
adapter,
327+
}: {
328+
sideChannels: SideChannelState;
329+
prompt: string;
330+
platformPreview: string;
331+
adapter: AdapterName;
332+
}): string[] {
333+
const tokenCount = prompt.length;
334+
const lines = [`prompt_ids shape=(1,${tokenCount}) dtype=int32`];
335+
if (sideChannels.inference.source === "none") {
336+
lines.push("side_channels=none");
337+
return lines;
338+
}
339+
340+
if (sideChannels.families.platform?.mode !== "off" && platformPreview) {
341+
lines.push("platform_ids shape=(1,5) family=platform dtype=int32");
342+
}
343+
344+
const parsesSource = (
345+
adapter !== "none" &&
346+
["parse_if_possible", "project_index", "auto"].includes(
347+
sideChannels.inference.source,
348+
)
349+
);
350+
if (parsesSource && sideChannels.families.structure?.mode !== "off") {
351+
lines.push(`structure_ids shape=(1,${tokenCount}) family=structure dtype=int32`);
352+
lines.push(`dep_levels shape=(1,${tokenCount}) family=structure dtype=int32`);
353+
}
354+
if (parsesSource && sideChannels.families.syntax?.mode !== "off") {
355+
lines.push(`ast_depth_ids shape=(1,${tokenCount}) family=syntax dtype=int32`);
356+
lines.push(`sibling_index_ids shape=(1,${tokenCount}) family=syntax dtype=int32`);
357+
lines.push(`node_type_ids shape=(1,${tokenCount}) family=syntax dtype=int32`);
358+
}
359+
360+
if (lines.length === 1) lines.push("side_channels=none");
361+
return lines;
362+
}
363+
308364
function renderPlatform(platform: Record<string, string>): string {
309365
return Object.entries(platform)
310366
.filter(([, value]) => value.trim().length > 0)

vbgui/tests/Sidebar.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ describe("SideChannelsTab", () => {
244244
.toContain("source=parse_if_possible");
245245
});
246246

247+
it("runs enriched preview and renders generated tensor summaries", () => {
248+
render(<SideChannelsTab sideChannels={INITIAL_SPEC.side_channels}
249+
availableChannels={["platform_ids"]}
250+
selectedTrainChannels={[]}
251+
gotchas={[]}
252+
onApply={() => {}}
253+
onTrainChannelsChange={() => {}} />);
254+
fireEvent.change(screen.getByTestId("side-channel-inference-source"),
255+
{ target: { value: "parse_if_possible" } });
256+
fireEvent.change(screen.getByTestId("side-channel-preview-prompt"),
257+
{ target: { value: "int x;" } });
258+
fireEvent.click(screen.getByTestId("side-channel-preview-run"));
259+
260+
const tensors = screen.getByTestId("side-channel-preview-tensors");
261+
expect(tensors.textContent).toContain("prompt_ids shape=(1,6)");
262+
expect(tensors.textContent).toContain("platform_ids shape=(1,5)");
263+
expect(tensors.textContent).toContain("structure_ids shape=(1,6)");
264+
expect(tensors.textContent).toContain("ast_depth_ids shape=(1,6)");
265+
});
266+
247267
it("surfaces required-family contract probe errors", () => {
248268
render(<SideChannelsTab sideChannels={INITIAL_SPEC.side_channels}
249269
availableChannels={[]}

0 commit comments

Comments
 (0)