summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/tests/logic.test.ts
diff options
context:
space:
mode:
authorMorgan Lunt <morganl@anthropic.com>2026-09-24 18:19:16 -0700
committerMorgan Lunt <morganl@anthropic.com>2026-09-24 18:19:16 -0700
commit54772aaaabf371dc212480fbf7da216bd65990c7 (patch)
treedf16d07b32801b695d616f16d87c1ad1a37739b5 /plugins/code-modernization/tests/logic.test.ts
parentc9e990089c6c87cb96e227e998edbada1df82861 (diff)
code-modernization: mark the pane's notes as data and clean the names in them
The pane adds two kinds of text to what the model reads: a note about the file it just read (names, rule titles and delta ids from the analysis files) and a one-line state. Those names were written by analysis agents from the legacy code, so a hostile comment could reach the model through them. Each such value is now cut to one short plain line: control, invisible and bidirectional characters, backticks, angle and square brackets and double quotes are replaced, and long values are trimmed. A note opens by saying its contents are data, never instructions, and closes with an end line no value can forge. The state line says it is a status line and not an instruction, and the next-step command names a module only when the module id is one plain token. The pane lists only system directories whose names the plugin's workflows accept.
Diffstat (limited to 'plugins/code-modernization/tests/logic.test.ts')
-rw-r--r--plugins/code-modernization/tests/logic.test.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/plugins/code-modernization/tests/logic.test.ts b/plugins/code-modernization/tests/logic.test.ts
index f4c258e9..2677118a 100644
--- a/plugins/code-modernization/tests/logic.test.ts
+++ b/plugins/code-modernization/tests/logic.test.ts
@@ -23,6 +23,7 @@ import { citationsIn, idOfTitle, needsReview, parseRules } from '../hooks/reader
import { nodeOfFile, parseTopology } from '../hooks/reader/topology'
import { decide, ledgerMarkdown, nextUnreviewed, queueOf, undecide } from '../hooks/review/deck'
import { signBrief } from '../hooks/sign'
+import { isSystemName, isToken, plain } from '../hooks/text'
import { readTestRun, TEST_COMMAND } from '../hooks/tests-run'
import { wrapLines } from '../hooks/views/deck'
import { BRIEF_SIGNED, BRIEF_UNSIGNED, RULES, RULES_BR, RULES_LABELLED, TOPOLOGY } from './fixtures/workspace'
@@ -568,3 +569,38 @@ describe('estate', () => {
expect(atob(still.cells).length).toBe(40 * 8 * 12)
})
})
+
+describe('text from the analysis files', () => {
+ test('a value becomes one short plain line', () => {
+ expect(plain(' Monthly interest\n\tis truncated ')).toBe('Monthly interest is truncated')
+ expect(plain('a`b`<system>c</system>[d]"e"')).toBe("a_b__system_c_/system__d_'e'")
+ expect(plain('x'.repeat(200), 20)).toBe(`${'x'.repeat(19)}…`)
+ expect(plain(42)).toBe('')
+ expect(plain(undefined)).toBe('')
+ })
+
+ test('nothing invisible survives: zero-width, bidirectional and tag characters, and line separators', () => {
+ const hidden = String.fromCodePoint(0x200b, 0x202e, 0x2066, 0xfeff, 0x2028, 0xe0041, 0xe0042, 0x00ad, 0x0085)
+
+ expect(plain(`a${hidden}b`)).toBe('a b')
+ expect(plain(`before${String.fromCodePoint(0xe0049)}after`)).toBe('before after')
+ })
+
+ test('a token is one plain word, a system name is what the workflows accept', () => {
+ for (const ok of ['INTCALC', 'shop-core', 'ds:RATES', 'com.acme.Foo', 'src/main/Foo.java', 'PAY#01', 'a@b']) {
+ expect(isToken(ok), ok).toBe(true)
+ }
+
+ for (const bad of ['', '-rf', 'a b', 'a;b', 'a|b', '$(id)', 'a`b`', "it's", 'a"b"', '~x', 'x'.repeat(81), 'new\nline', '.hidden']) {
+ expect(isToken(bad), JSON.stringify(bad)).toBe(false)
+ }
+
+ for (const ok of ['carddemo', 'shop-web', 'a_b', 'A1']) {
+ expect(isSystemName(ok), ok).toBe(true)
+ }
+
+ for (const bad of ['my system', 'a.b', '-x', '_x', 'a/b', 'a;b', '']) {
+ expect(isSystemName(bad), JSON.stringify(bad)).toBe(false)
+ }
+ })
+})