// Session titles must not start with the machine name. stripDevicePrefix is private to // index.js, so the test extracts its source and evaluates it. import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' const src = fs.readFileSync(new URL('../index.js', import.meta.url), 'utf8') const m = src.match(/const stripDevicePrefix = [\s\S]*?\n}\n/) assert.ok(m, 'stripDevicePrefix not found in index.js') const stripDevicePrefix = new Function(`${m[0]}; return stripDevicePrefix`)() test('removes a leading machine name with common separators', () => { const names = ['ai-pc', 'AI PC'] assert.equal(stripDevicePrefix('ai-pc: git pull + unit tests', names), 'git pull + unit tests') assert.equal(stripDevicePrefix('AI-PC - run tests', names), 'run tests') assert.equal(stripDevicePrefix('[ai-pc] run tests', names), 'run tests') assert.equal(stripDevicePrefix('(ai-pc) ยท run tests', names), 'run tests') assert.equal(stripDevicePrefix('ai-pc | run tests', names), 'run tests') assert.equal(stripDevicePrefix('ai-pc> run tests', names), 'run tests') }) test('keeps titles that merely mention the machine, and empty titles', () => { const names = ['ai-pc'] assert.equal(stripDevicePrefix('Test and fix ai-pc deployment', names), 'Test and fix ai-pc deployment') assert.equal(stripDevicePrefix('ai-pc deployment notes', names), 'ai-pc deployment notes') assert.equal(stripDevicePrefix('Clone and test ai-pc repository remotely', names), 'Clone and test ai-pc repository remotely') assert.equal(stripDevicePrefix('', names), '') assert.equal(stripDevicePrefix(null, names), '') }) test('strips every known name, not only the first', () => { assert.equal(stripDevicePrefix('Pelican-Node: backup', ['pelican-node', 'Pelican-Node']), 'backup') assert.equal(stripDevicePrefix('mac: backup', ['mac', 'my-mac']), 'backup') })