Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(window): verify evidence and report desktop capability failures

Linuxdazhaobf82fee87128
diff --git a/.github/workflows/windows-native-snap.yml b/.github/workflows/windows-native-snap.yml
index f05ba1cf9..1b59e1bd3 100644
--- a/.github/workflows/windows-native-snap.yml
+++ b/.github/workflows/windows-native-snap.yml
@@ -51,6 +51,8 @@ jobs:
run: pnpm install --frozen-lockfile
- name: Build workspace fixture dependencies
run: pnpm build:js
+ - name: Verify preserved original-head evidence
+ run: node --test apps/desktop/test/window-native-snap-evidence.test.mjs
- name: Install pinned Electron
run: pnpm --filter @pi-desktop/desktop exec install-electron
- name: Build native Host
diff --git a/apps/desktop/test/window-native-snap-evidence.test.mjs b/apps/desktop/test/window-native-snap-evidence.test.mjs
new file mode 100644
index 000000000..78ce01358
--- /dev/null
+++ b/apps/desktop/test/window-native-snap-evidence.test.mjs
@@ -0,0 +1,36 @@
+import assert from "node:assert/strict";
+import { createHash } from "node:crypto";
+import { readFile } from "node:fs/promises";
+import test from "node:test";
+
+const evidence = new URL("../../../docs/project/windows-native-snap-evidence/38c5a5bd77ef/", import.meta.url);
+const json = async (name) => JSON.parse(await readFile(new URL(name, evidence), "utf8"));
+
+test("preserved native evidence verifies after checkout without changing stream bytes", async () => {
+ const manifest = await json("manifest.json");
+ assert.equal(manifest.sourceRevision, "38c5a5bd77ef910849ce3c1bc5f5d8577dad1a71");
+ for (const [name, expected] of Object.entries(manifest.files)) {
+ const bytes = await readFile(new URL(name, evidence));
+ assert.equal(createHash("sha256").update(bytes).digest("hex"), expected, name);
+ }
+});
+
+test("preserved baseline and candidate describe the same native snap regression", async () => {
+ const baseline = await json("baseline.json");
+ const candidate = await json("candidate.json");
+ assert.equal(baseline.ok, false);
+ assert.match(baseline.error, /Win\+Left did not snap to the work-area half/);
+ assert.deepEqual(baseline.left, baseline.before);
+ assert.equal(candidate.ok, true);
+ assert.ok(candidate.checks >= 121);
+ assert.equal(candidate.environment.electronVersion, baseline.environment.electronVersion);
+ assert.deepEqual(candidate.environment.workArea, baseline.environment.workArea);
+ const area = candidate.environment.workArea;
+ for (const state of ["keyboardMaximized", "maximized", "restoredMaximized"]) {
+ const bounds = candidate[state];
+ assert.deepEqual([bounds.clientX, bounds.clientY, bounds.clientWidth, bounds.clientHeight],
+ [area.x, area.y, area.width, area.height]);
+ assert.deepEqual([bounds.visibleX, bounds.visibleY, bounds.visibleWidth, bounds.visibleHeight],
+ [area.x, area.y, area.width, area.height]);
+ }
+});
diff --git a/scripts/e2e-window-snap.mjs b/scripts/e2e-window-snap.mjs
index d276ef998..db1995a6a 100644
--- a/scripts/e2e-window-snap.mjs
+++ b/scripts/e2e-window-snap.mjs
@@ -40,6 +40,7 @@ await copyFile(join(root, "scripts/e2e/run-window-snap.ps1"), join(directory, "r
const git = async (...args) => (await run("git", args, { cwd: root })).stdout.trim();
const files = ["scripts/e2e-window-snap.mjs", "scripts/e2e/run-window-snap.ps1", "scripts/e2e/probe-window-snap.cs",
"scripts/e2e/fixtures/window-snap/main.cjs", "scripts/e2e/host.mjs", "pnpm-lock.yaml", "Cargo.lock",
+ "Cargo.toml", "crates/host-core/Cargo.toml", ".cargo/config.toml",
"apps/desktop/package.json", "apps/desktop/electron/main/window-native-snap.ts",
"apps/desktop/electron/main/window-native-corners.ts", "apps/desktop/electron/main/window-native-handle.ts",
"apps/desktop/electron/main/window-fullscreen.ts", "apps/desktop/electron/main/window-shape.ts",
@@ -48,6 +49,7 @@ const hashes = {};
for (const file of files) hashes[file] = createHash("sha256").update(await readFile(join(root, file))).digest("hex");
await writeFile(join(directory, "source.json"), JSON.stringify({
revision: await git("rev-parse", "HEAD"), tree: await git("rev-parse", "HEAD^{tree}"),
+ hostTree: await git("rev-parse", "HEAD:crates/host-core"),
clean: (await git("status", "--porcelain", "--untracked-files=no")) === "", hashes,
}, null, 2));
await writeFile(join(directory, "options.json"), JSON.stringify({
diff --git a/scripts/e2e/probe-window-snap.cs b/scripts/e2e/probe-window-snap.cs
index 7245251f8..3efe6b92c 100644
--- a/scripts/e2e/probe-window-snap.cs
+++ b/scripts/e2e/probe-window-snap.cs
@@ -30,6 +30,10 @@ public static class WindowSnapProbe {
[DllImport("user32.dll")] static extern IntPtr SetThreadDpiAwarenessContext(IntPtr context);
[DllImport("user32.dll",SetLastError=true)] static extern IntPtr OpenInputDesktop(uint flags,bool inherit,uint access);
[DllImport("user32.dll")] static extern bool CloseDesktop(IntPtr desktop);
+ [DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr window);
+ [DllImport("user32.dll")] static extern int ReleaseDC(IntPtr window,IntPtr dc);
+ [DllImport("gdi32.dll")] static extern int GetDeviceCaps(IntPtr dc,int index);
+ [DllImport("dwmapi.dll")] static extern int DwmIsCompositionEnabled(out bool enabled);
[DllImport("dwmapi.dll")] static extern int DwmGetWindowAttribute(IntPtr h, int attribute, out SnapRect r, int size);
[DllImport("dwmapi.dll",EntryPoint="DwmGetWindowAttribute")] static extern int DwmGetColor(IntPtr h, int attribute, out uint color, int size);
static readonly string Root = AppDomain.CurrentDomain.BaseDirectory;
@@ -178,6 +182,10 @@ public static class WindowSnapProbe {
var desktop=OpenInputDesktop(0,false,0x101);
Check(desktop!=IntPtr.Zero,"the interactive input desktop is unavailable or locked");
CloseDesktop(desktop);
+ var dc=GetDC(IntPtr.Zero);
+ try { Result["desktopBitsPerPixel"]=GetDeviceCaps(dc,12)*GetDeviceCaps(dc,14); }
+ finally { ReleaseDC(IntPtr.Zero,dc); }
+ bool composition;Result["dwmCompositionResult"]=DwmIsCompositionEnabled(out composition);Result["dwmComposition"]=composition;
SetThreadDpiAwarenessContext(new IntPtr(-4));
var options=Read("options.json"); bool baseline=(bool)options["baseline"];
externalPointer=options.ContainsKey("externalPointer") && (bool)options["externalPointer"];
diff --git a/scripts/e2e/run-window-snap.ps1 b/scripts/e2e/run-window-snap.ps1
index b326fdf09..cd3dde1be 100644
--- a/scripts/e2e/run-window-snap.ps1
+++ b/scripts/e2e/run-window-snap.ps1
@@ -71,20 +71,23 @@ try {
if (-not $completed) { throw "$case native probe timed out; see retained artifacts." }
$result = Get-Content (Join-Path $evidence 'result.json') -Raw | ConvertFrom-Json
if ($case -eq 'baseline' -and $Matrix) {
- $unchanged = $true
- foreach ($field in @('x', 'y', 'width', 'height')) {
- if ($result.before.$field -ne $result.left.$field) { $unchanged = $false }
+ $passed = $false
+ if ($result.before -and $result.left -and $result.before.style -match '^0x[0-9A-Fa-f]{8}$') {
+ $unchanged = $true
+ foreach ($field in @('x', 'y', 'width', 'height')) {
+ if ($result.before.$field -ne $result.left.$field) { $unchanged = $false }
+ }
+ $style = [Convert]::ToUInt32($result.before.style.Substring(2), 16)
+ $passed = ($result.ok -eq $false -and $result.baseline -eq $true -and
+ $result.failure -ceq 'Win+Left did not snap to the work-area half' -and
+ $unchanged -and ($style -band 0x00C40000) -eq 0)
}
- $style = [Convert]::ToUInt32($result.before.style.Substring(2), 16)
- $passed = ($result.ok -eq $false -and $result.baseline -eq $true -and
- $result.failure -ceq 'Win+Left did not snap to the work-area half' -and
- $unchanged -and ($style -band 0x00C40000) -eq 0)
} else {
$passed = ($result.ok -eq $true -and $result.baseline -eq $false)
}
$summary.cases += [ordered]@{ name = $case; runId = $result.runId; passed = $passed; checks = $result.checks }
Write-RunnerLog ($case + ' passed=' + $passed + ' checks=' + $result.checks)
- if (-not $passed) { throw "$case did not satisfy its acceptance contract; see retained artifacts." }
+ if (-not $passed) { throw "$case did not satisfy its acceptance contract: $($result.failure); see retained artifacts." }
}
$summary.ok = $true
} catch {