Personal Telegram developer console for GitHub

feat/studio-g0-foundation
audit/commit-drilldown audit/finalize-workspace-menu-security audit/ops-actionability audit/pr-menu-consolidation audit/status-menu-consolidation audit/telegram-menu-e2e audit/telegram-menu-e2e-wave2 chore/actions-node24-runtime cleanup/remove-diag design/cloudflare-ops-read docs/control-plane-2-7-design docs/guide-v2-1-sync docs/menu-audit-final-sync docs/phase2-acceptance-closeout docs/phase2-multifile-design feat/bootstrap-worker feat/cloudflare-ops-read feat/cp2-multifile-final feat/cp2-multifile-workspace feat/cp3-github-write-final feat/cp4-cloudflare-ops-final feat/cp5-cicd-control-plane feat/cp6-incident-manager feat/cp7-automation-engine feat/deep-file-browser feat/final-delivery-16-20 feat/github-advanced-read feat/in-app-guide-v2 feat/navigation-recovery-ux-v2 feat/ops-console-v2-1 feat/persistent-menu-code-input feat/phase2-multifile-workspace feat/phase2-multifile-workspace-v2 feat/plugin-foundation-v1 feat/safe-github-ops feat/self-register-webhook feat/studio-g0-foundation feat/telegram-main-inline-menu feat/telegram-pr-merge feat/ux-platform-8-12 feat/v3a-readonly-copilot feat/workspace-file-upload feature/mobile-repo-browser feature/multi-file-change-set fix/approval-expiry-feedback fix/callback-resilience-and-docs fix/ci-actions-pagination fix/cloudflare-fetch-binding fix/editor-request-body-cap fix/editor-safe-file-options fix/issues-permission-release-empty-ux fix/main-menu-callback-fallback fix/phase2-file-editor-selection fix/phase2-final-ux fix/phase2-workspace-ref-persistence fix/production-auto-deploy fix/provider-write-error-feedback fix/repository-id-navigation-fallback fix/repository-pr-navigation fix/telegram-callback-updates fix/telegram-runtime-diagnostics fix/workspace-editor-flow-v2 fix/workspace-recovery-validation hardening/ci-zero-test-telegram-token hardening/pr1-destructive-totp hardening/pr2-kill-switch main multifile-workspace nexa/edit-BwJEIIY3PW nexa/edit-IPHT8irO7b nexa/edit-b4Od3BIMYd p2-multifile phase2-20261005 phase2-20261005-a phase2-20261005-b phase2-20261005-c phase2-20261005-d phase2-20261005-e phase2-20261005-f phase2-20261005-g phase2-20261005-h phase2-20261005-i phase2-20261005-j phase2-20261005-k phase2-20261005-l phase2-20261005-m phase2-20261005-n phase2-20261005-o phase2-20261005-p phase2-20261005-q phase2-20261005-r phase2-20261005-s phase2-20261005-t phase2-20261005-u phase2-20261005-v phase2-20261005-w phase2-20261005-x phase2-20261005-y phase2-20261005-z phase2-acceptance-closeout phase2-add-file-hotfix phase2-change-set phase2-design-20261005 phase2-design-final phase2-implementation phase2-multifile-implementation phase2-multifile-spec phase2-spec-final phase2-workspace phase2/multifile-workspace plan/nexa-studio-v2-reviewed security/remove-telegram-setup spec/repository-workspace-editor v3a/multifile work/multifile
js 148 lines 4.9 KB
Raw
1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3
4 let policy = {};
5 try {
6 policy = await import('../src/core/workspace-policy.js');
7 } catch {
8 policy = {};
9 }
10
11 const requireFn = (name) => {
12 assert.equal(typeof policy[name], 'function', `${name} must be implemented`);
13 return policy[name];
14 };
15
16 test('editable file policy accepts bounded UTF-8 text', () => {
17 const validateEditableFile = requireFn('validateEditableFile');
18 const result = validateEditableFile({
19 path: 'src/app.js',
20 text: 'export const ok = true;\n'
21 });
22 assert.deepEqual(result, {
23 editable: true,
24 reason: '',
25 text: 'export const ok = true;\n',
26 charLength: 24,
27 byteLength: 24
28 });
29 });
30
31 test('editable file policy rejects sensitive paths binary markers LFS and both size ceilings', () => {
32 const validateEditableFile = requireFn('validateEditableFile');
33 for (const path of [
34 '.env',
35 '.env.production',
36 'keys/id_rsa',
37 'id_ed25519',
38 'tls/cert.pem',
39 'tls/private.key',
40 'a.p12',
41 'a.pfx',
42 'credentials.json',
43 'service-account-prod.json'
44 ]) {
45 const result = validateEditableFile({ path, text: 'safe-looking text' });
46 assert.equal(result.editable, false, path);
47 assert.match(result.reason, /sensitive/i);
48 }
49
50 const binary = validateEditableFile({ path: 'data.txt', text: 'abc\0def' });
51 assert.equal(binary.editable, false);
52 assert.match(binary.reason, /binary/i);
53
54 const lfs = validateEditableFile({
55 path: 'asset.txt',
56 text: 'version https://git-lfs.github.com/spec/v1\noid sha256:abc\nsize 123\n'
57 });
58 assert.equal(lfs.editable, false);
59 assert.match(lfs.reason, /LFS/i);
60
61 const tooManyChars = validateEditableFile({
62 path: 'large.txt',
63 text: 'a'.repeat(20001)
64 });
65 assert.equal(tooManyChars.editable, false);
66 assert.match(tooManyChars.reason, /20,000|20000/);
67
68 const explicitTooManyBytes = validateEditableFile({
69 path: 'large.txt',
70 text: 'ok',
71 byteLength: 65537
72 });
73 assert.equal(explicitTooManyBytes.editable, false);
74 assert.match(explicitTooManyBytes.reason, /65,536|65536/);
75 });
76
77 test('editable file policy enforces multibyte UTF-8 byte boundary independently from character boundary', () => {
78 const validateEditableFile = requireFn('validateEditableFile');
79 const exact = '😀'.repeat(16384);
80 const exactResult = validateEditableFile({ path: 'emoji.txt', text: exact });
81 assert.equal(exactResult.charLength, 16384);
82 assert.equal(exactResult.byteLength, 65536);
83 assert.equal(exactResult.editable, true);
84
85 const over = `${exact}a`;
86 const overResult = validateEditableFile({ path: 'emoji.txt', text: over });
87 assert.equal(overResult.charLength, 16385);
88 assert.equal(overResult.byteLength, 65537);
89 assert.equal(overResult.editable, false);
90 assert.match(overResult.reason, /65,536|65536/);
91 });
92
93 test('commit message and target branch normalization fail closed on empty or unsafe values', () => {
94 const normalizeCommitMessage = requireFn('normalizeCommitMessage');
95 const makeTargetBranch = requireFn('makeTargetBranch');
96
97 assert.equal(
98 normalizeCommitMessage(' test: verify mobile editor '),
99 'test: verify mobile editor'
100 );
101 assert.throws(() => normalizeCommitMessage(' '), /commit message/i);
102 assert.throws(() => normalizeCommitMessage('x'.repeat(121)), /120/);
103
104 assert.equal(makeTargetBranch('Ab3_-xYz09'), 'nexa/edit-Ab3_-xYz09');
105 assert.throws(() => makeTargetBranch('../bad'), /workspace/i);
106 assert.throws(() => makeTargetBranch('short'), /workspace/i);
107 });
108
109 test('unified diff reports exact additions deletions and marks bounded truncation without changing counts', () => {
110 const buildUnifiedDiff = requireFn('buildUnifiedDiff');
111 const before = 'alpha\nbeta\ngamma\n';
112 const after = 'alpha\nBETA\ngamma\ndelta\n';
113 const full = buildUnifiedDiff({
114 path: 'src/app.js',
115 before,
116 after,
117 maxChars: 2600
118 });
119 assert.equal(full.additions, 2);
120 assert.equal(full.deletions, 1);
121 assert.equal(full.truncated, false);
122 assert.match(full.text, /--- a\/src\/app\.js/);
123 assert.match(full.text, /\+\+\+ b\/src\/app\.js/);
124 assert.match(full.text, /-beta/);
125 assert.match(full.text, /\+BETA/);
126 assert.match(full.text, /\+delta/);
127
128 const bounded = buildUnifiedDiff({
129 path: 'src/app.js',
130 before: Array.from({ length: 250 }, (_, i) => `old-${i}`).join('\n'),
131 after: Array.from({ length: 250 }, (_, i) => `new-${i}`).join('\n'),
132 maxChars: 120
133 });
134 assert.equal(bounded.additions, 250);
135 assert.equal(bounded.deletions, 250);
136 assert.equal(bounded.truncated, true);
137 assert.ok(bounded.text.length <= 120);
138 });
139
140 test('digestText is stable for identical content and changes with content', async () => {
141 const digestText = requireFn('digestText');
142 const first = await digestText('hello');
143 const second = await digestText('hello');
144 const changed = await digestText('hello!');
145 assert.match(first, /^[a-f0-9]{64}$/);
146 assert.equal(first, second);
147 assert.notEqual(first, changed);
148 });