| 1 | import test from 'node:test' |
| 2 | import assert from 'node:assert/strict' |
| 3 | import {insideKey,pathKey,samePath,stripVerbatim,unlinkedKeyMatches} from '../dist/shell-hooks.mjs' |
| 4 | |
| 5 | // Pure string normalization: runs on every OS by naming the platform. |
| 6 | test('win32 canonical compare ignores the verbatim prefix and case, never the path itself',()=>{ |
| 7 | assert.equal(stripVerbatim('\\\\?\\C:\\Users\\runneradmin\\x','win32'),'C:\\Users\\runneradmin\\x') |
| 8 | assert.equal(stripVerbatim('\\\\?\\UNC\\host\\share\\x','win32'),'\\\\host\\share\\x') |
| 9 | assert.ok(samePath('\\\\?\\C:\\Users\\RunnerAdmin\\Bundle\\hooks.json','c:\\users\\runneradmin\\bundle\\hooks.json','win32')) |
| 10 | assert.equal(pathKey('\\\\?\\C:\\A\\B','win32'),pathKey('c:\\a\\b','win32')) |
| 11 | assert.ok(!samePath('C:\\a\\b','C:\\a\\c','win32')) |
| 12 | // Case folds only on win32. |
| 13 | assert.ok(!samePath('/a/B','/a/b','linux')) |
| 14 | // Containment against a differently spelled canonical root keeps the target's case. |
| 15 | assert.equal(insideKey('\\\\?\\C:\\Users\\RUNNERADMIN\\bundle','c:\\users\\runneradmin\\bundle\\Mod\\a.js','win32'),'Mod/a.js') |
| 16 | assert.equal(insideKey('C:\\bundle','C:\\bundle-evil\\a.js','win32'),undefined) |
| 17 | assert.equal(insideKey('C:\\bundle','D:\\bundle\\a.js','win32'),undefined) |
| 18 | assert.equal(insideKey('/r','/r/../x','linux'),undefined) |
| 19 | // A file is unlinked when its canonical path is the canonical root joined with its reviewed key. |
| 20 | assert.ok(unlinkedKeyMatches('\\\\?\\C:\\Users\\runneradmin\\bundle','hooks.json','C:\\USERS\\RunnerAdmin\\Bundle\\HOOKS.JSON','win32')) |
| 21 | assert.ok(!unlinkedKeyMatches('C:\\bundle','link.json','C:\\bundle\\hooks.json','win32')) |
| 22 | assert.ok(!unlinkedKeyMatches('C:\\bundle','../x.json','C:\\x.json','win32')) |
| 23 | assert.ok(!unlinkedKeyMatches('/r','link.json','/r/hooks.json','linux')) |
| 24 | }) |
| 25 |