gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain5d144817Merge branch 'records-t40' into mainTicketsmain/plugins/fs/tests/listdir-lifetime.mjs

2.1 KB

  1. import assert from 'node:assert/strict';
  2. import { mkdtempSync, writeFileSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
  3. import { spawnSync } from 'node:child_process';
  4. import { join, resolve } from 'node:path';
  5. const root = resolve(import.meta.dirname, '../../..');
  6. const bin = process.env.HL_BIN || join(root, 'native/zig-out/bin/hybriel');
  7. const work = mkdtempSync(join(process.env.TMPDIR, 'listdir-lifetime-'));
  8. try {
  9. const dir = join(work, 'entries');
  10. mkdirSync(dir);
  11. for (let i = 0; i < 150; i++) writeFileSync(join(dir, String(i).padStart(64, '0') + '.txt'), 'abc');
  12. const expected = readdirSync(dir, { withFileTypes: true }).map(e => e.name);
  13. const source = join(work, 'walk.hl');
  14. writeFileSync(source, `import { listDir, writeFile } from 'hl:fs'
  15. import { args } from 'hl:proc'
  16. a = args()
  17. let rows = []
  18. iterator = listDir(a[0])
  19. writeFile(a[0] + '/late.txt', 'late')
  20. for (entry of iterator) { rows.push(entry) }
  21. console.log(JSON.stringify(rows))
  22. let early = ''
  23. for (entry of listDir(a[0])) { early = entry.name
  24. break }
  25. console.log(early)
  26. `);
  27. const native = join(work, 'walk');
  28. const build = spawnSync(bin, ['--native', source, '-o', native], { encoding: 'utf8' });
  29. assert.equal(build.status, 0, build.stdout + build.stderr);
  30. const run = spawnSync(native, [dir], { encoding: 'utf8' });
  31. assert.equal(run.status, 0, run.stdout + run.stderr);
  32. const [json, first] = run.stdout.trim().split('\n');
  33. const rows = JSON.parse(json);
  34. assert.deepEqual(rows.map(e => e.name).sort(), expected.sort());
  35. for (const e of rows) {
  36. assert.equal(e.path, join(dir, e.name));
  37. assert.equal(e.type, 'file');
  38. assert.equal(e.size, 3);
  39. assert.equal(e.mime, 'text/plain');
  40. assert.equal(typeof e.chmod, 'number');
  41. assert.equal(e.user, process.getuid());
  42. assert.equal(e.group, process.getgid());
  43. assert.deepEqual(Object.keys(e).sort(), ['chmod', 'group', 'mime', 'name', 'path', 'size', 'type', 'user']);
  44. }
  45. assert.ok(expected.includes(first) || first === 'late.txt');
  46. console.log('listDir: 150 retained eight-field entries survive exhaustion; call-time snapshot and early exit pass');
  47. } finally { rmSync(work, { recursive: true, force: true }); }

Branches

Latest commits

  • 5d144817Merge branch 'records-t40' into mainTickets
  • 44ee6f06|||PR records: #43 #45 livemre
  • b8fdeee9Merge branch 'p39-routes' into mainTickets
  • a0187a0a|||PR Remove redundant route-order loopmre
  • 369e4b9cMerge branch 'k40-lists' into mainTickets
  • 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
  • 610d8e8aMerge branch 'records-t39' into mainTickets
  • 32bcdf24|||PR records: GO P39 K40mre
  • 4123c6d1Merge branch 'records-t38' into mainTickets
  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre