Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: opt-in Windows Recycle Bin smoke for the native trash adapter (#12325)

Adam Eivyd84926bef84f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8d4c805675..a6de8b765a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1127,6 +1127,8 @@ jobs:
# Windows runners lose Vitest workers at startup with 0xC0000142
# (STATUS_DLL_INIT_FAILED) under per-file process churn (#10114).
PORTOS_CI_MAX_WORKERS: 2
+ # Opts nativeTrash.smoke.test.js into the runner's real Recycle Bin (#12325).
+ PORTOS_NATIVE_TRASH_SMOKE: 1
run: node scripts/run-ci-tests.js server
- name: Save the test memo
diff --git a/docs/research/assets/native-trash-poc/README.md b/docs/research/assets/native-trash-poc/README.md
index 5dbabb8774..1849ab6aa8 100644
--- a/docs/research/assets/native-trash-poc/README.md
+++ b/docs/research/assets/native-trash-poc/README.md
@@ -15,3 +15,8 @@ removes everything it created, including from the Trash / Recycle Bin.
These are investigation tools, not product code: nothing under `server/` imports
them, and the implementation plan in the ADR owns the production versions.
+
+The Windows CI job also runs `server/lib/nativeTrash.smoke.test.js` against the
+runner's real Recycle Bin (opt-in via `PORTOS_NATIVE_TRASH_SMOKE=1`, set only on the
+`windows-server` job). It recycles one temp file through the shipped adapter, asserts the
+`$I` record names the original path, and removes its own `$I`/`$R` pair.
diff --git a/server/lib/nativeTrash.smoke.test.js b/server/lib/nativeTrash.smoke.test.js
new file mode 100644
index 0000000000..16783bafa7
--- /dev/null
+++ b/server/lib/nativeTrash.smoke.test.js
@@ -0,0 +1,48 @@
+// Opt-in real Recycle Bin check for the Windows CI job (issue #12325). The
+// mocked suite in nativeTrash.test.js cannot notice a Windows update breaking
+// the shipped windows-trash.exe, and a developer's real bin must stay untouched
+// unless they set PORTOS_NATIVE_TRASH_SMOKE themselves.
+import { afterEach, describe, expect, it } from 'vitest';
+import { mkdtemp, readdir, readFile, rm, stat, unlink, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join, parse } from 'node:path';
+import { execFileSync } from './childProcess.js';
+import { moveToNativeTrash } from './nativeTrash.js';
+
+// $I<id>: 8-byte version, 8-byte size, 8-byte FILETIME, then (version 2) a
+// 4-byte path length and the UTF-16LE original path; version 1 is a padded path.
+const readOriginalPath = (buf) => (buf.readBigUInt64LE(0) >= 2n
+ ? buf.toString('utf16le', 28, 28 + (buf.readUInt32LE(24) - 1) * 2)
+ : buf.toString('utf16le', 24).replace(/\0.*$/s, ''));
+
+describe.runIf(process.platform === 'win32' && process.env.PORTOS_NATIVE_TRASH_SMOKE)('native recycling adapter on a real Recycle Bin', () => {
+ let dir;
+ let binDir;
+ let infoFile;
+ afterEach(async () => {
+ // Remove only the pair this test created, then its temp directory.
+ if (infoFile) {
+ await unlink(infoFile).catch(() => {});
+ await unlink(join(binDir, `$R${parse(infoFile).base.slice(2)}`)).catch(() => {});
+ }
+ await rm(dir, { recursive: true, force: true });
+ });
+
+ it('recycles a temp file and leaves a $I record naming its original path', async () => {
+ dir = await mkdtemp(join(tmpdir(), 'portos-native-trash-smoke-'));
+ const file = join(dir, 'smoke target.txt');
+ await writeFile(file, 'native trash smoke');
+ const sid = execFileSync('whoami', ['/user', '/fo', 'csv', '/nh'], { encoding: 'utf8', windowsHide: true })
+ .trim().split(',')[1].replaceAll('"', '');
+ binDir = join(parse(file).root, '$Recycle.Bin', sid);
+
+ await moveToNativeTrash([file]);
+
+ await expect(stat(file)).rejects.toMatchObject({ code: 'ENOENT' });
+ for (const name of await readdir(binDir)) {
+ if (!name.startsWith('$I')) continue;
+ if (readOriginalPath(await readFile(join(binDir, name))).toLowerCase() === file.toLowerCase()) infoFile = join(binDir, name);
+ }
+ expect(infoFile, 'a $I record naming the recycled path').toBeDefined();
+ });
+});