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

Hash the forward-slashed shard path on every platform, as pathe's resolve does

[._.]/ Adam Eivyb3629cbfc3cf
diff --git a/scripts/lib/testMemoRunner.js b/scripts/lib/testMemoRunner.js
index 27b1679790..5244267265 100644
--- a/scripts/lib/testMemoRunner.js
+++ b/scripts/lib/testMemoRunner.js
@@ -110,17 +110,18 @@ export function vitestShardRange(count, index, total) {
}
/**
- * The string Vitest hashes for a test file when sharding:
- * `resolve(slash(root), slash(moduleId)).slice(root.length)` — the absolute
- * path as the platform's `path.resolve` builds it (backslashes on Windows)
- * with the root prefix sliced off, so an in-workspace file hashes as
- * `/lib/x.test.js` or `\\lib\\x.test.js` and a file outside the workspace
- * hashes its remaining absolute tail. `path` is injectable so both
- * separators are pinned in the tests.
+ * The string Vitest hashes for a test file when sharding (`BaseSequencer.shard`
+ * in vitest/dist/chunks/index.*.js): `resolve(slash(root), slash(moduleId))`
+ * with pathe's forward-slash `resolve`, sliced at `root.length` (the
+ * unslashed root has the same length). So on every platform an in-workspace
+ * file hashes as `/lib/x.test.js` and a file outside the workspace hashes the
+ * forward-slashed tail of its absolute path. `path` is injectable so a
+ * Windows-shaped root is pinned in the tests.
*/
export function vitestShardHashInput(rel, { repoRoot, scope, path = nodePath }) {
+ const slash = (value) => value.replace(/\\/g, '/');
const root = path.resolve(repoRoot, scope);
- return path.resolve(repoRoot, ...rel.split('/')).slice(root.length);
+ return slash(path.resolve(repoRoot, ...rel.split('/'))).slice(root.length);
}
/**
diff --git a/scripts/lib/testMemoRunner.test.js b/scripts/lib/testMemoRunner.test.js
index 206fa62fe4..448e79729e 100644
--- a/scripts/lib/testMemoRunner.test.js
+++ b/scripts/lib/testMemoRunner.test.js
@@ -140,16 +140,17 @@ describe('planTestMemo and recordTestMemo', () => {
expect(plan({ memoDir: null }).skipped).toEqual([]);
});
- it('hashes the root-relative path with the platform\'s own separator, like Vitest', () => {
- // POSIX: `/lib/x.test.js`; Windows: `\\lib\\x.test.js` (path.resolve builds a backslash path).
+ it('hashes the forward-slashed root-relative path on every platform, like Vitest', () => {
+ // pathe's resolve slashes before the slice, so a Windows root yields the same tail as a POSIX one.
expect(vitestShardHashInput('server/lib/x.test.js', { repoRoot: '/repo', scope: 'server', path: posix })).toBe('/lib/x.test.js');
expect(vitestShardHashInput('scripts/x.test.js', { repoRoot: '/repo', scope: 'server', path: posix })).toBe('s/x.test.js');
- expect(vitestShardHashInput('server/lib/x.test.js', { repoRoot: 'D:\\a\\repo', scope: 'server', path: win32 })).toBe('\\lib\\x.test.js');
- expect(vitestShardHashInput('scripts/x.test.js', { repoRoot: 'D:\\a\\repo', scope: 'server', path: win32 })).toBe('s\\x.test.js');
- // The two separators hash differently, so a slice computed for the other platform is not this platform's slice.
+ expect(vitestShardHashInput('server/lib/x.test.js', { repoRoot: 'D:\\a\\repo', scope: 'server', path: win32 })).toBe('/lib/x.test.js');
+ expect(vitestShardHashInput('scripts/x.test.js', { repoRoot: 'D:\\a\\repo', scope: 'server', path: win32 })).toBe('s/x.test.js');
+ // So the partition is the same on both platforms for the same repository layout.
const files = ['server/lib/a.test.js', 'server/lib/b.test.js', 'server/lib/c.test.js', 'scripts/d.test.js', 'scripts/e.test.js'];
const slices = (path, repoRoot) => [1, 2].map((index) => vitestShardSlice(files, { repoRoot, scope: 'server', index, count: 2, path }));
- for (const [a, b] of [slices(posix, '/repo'), slices(win32, 'D:\\a\\repo')]) expect([...a, ...b].sort()).toEqual([...files].sort());
+ expect(slices(win32, 'D:\\a\\repo')).toEqual(slices(posix, '/repo'));
+ expect(slices(posix, '/repo').flat().sort()).toEqual([...files].sort());
});
it('slices shards exactly like Vitest\'s sequencer', () => {