Session titles: strip a leading machine-name prefix
- remote_task strips the device name from the title it creates, and tells the model not to include it - session lists (Devices tab, sidebar, remote_devices) strip it from existing titles - tests for stripDevicePrefix
This commit is contained in:
1 parent
bf99a952fb
commit
0bef3b9fbe
2 files changed
+48
-3
No files matched your search
@@ -0,0 +1,34 @@
|
||||
// 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')
|
||||
})
|
||||
Reference in new issue
Block a user