Personal Telegram developer console for GitHub
test: verify editor filename behavior and document CI billing recovery
Codex committed
Oct 24, 2026 at 14:06 UTC
fd6c65d5a82ecaaf27f2171cd26237022124baf4
3 files changed
+167
-9
PROJECT_MEMORY.md
+11
@@ -15,6 +15,17 @@
15
4. Do not call a phase production-accepted from CI alone; deployment and owner-device/runtime evidence are separate gates.
16
5. Production WRITE / DESTRUCTIVE provider actions must remain behind Safe Approval and durable one-time replay protection.
17
18
+## Latest checkpoint — 2026-10-24, PR #63 verification recovery
19
+- Live `main` at investigation: `5d1c083d326db327cc3973a9d3adecc1d8092c91`; PR #63 remains on `fix/editor-safe-file-options`.
20
+- Actions CI run `40100142480`, job/check `120890430470`, on candidate `18f663c2962478f2016dfb309034277c18239e12` never received a runner and had zero steps. Its failure annotation explicitly reports failed recent account payments or a spending limit needing increase. This is an account billing blocker, not evidence that tests failed.
21
+- The original candidate's full suite passed locally on Node `22.23.4`: **268 tests, 0 failures/cancelled/skipped**. Wrangler `4.152.0` on Node 22 also completed `deploy --dry-run` with all five Durable Object bindings and no upload. Local checks do not replace PR/main CI or runtime verification.
22
+- A separate local jsdom `26.1.0` smoke executed the generated page with markup-shaped, quoted, entity and Unicode filenames. Exact option labels/values/count, selection, authenticated draft-save payload and absence of injected script execution were verified. This is DOM emulation, not owner-device browser/Telegram acceptance.
23
+- Three independent AI-agent reviews covered security, test behavior and release operations for that candidate. No blocking code regression was found; these are not submitted GitHub or human approvals. Reviewers recommended behavioral coverage beyond the two original source-pattern tests.
24
+- Recovery changes replace regex-only coverage with four executed-script behavior tests plus one construction guard: literal filename labels/values and selection, authenticated draft saving, legacy single-file fallback and navigation/reload. Final local Node 22 suite: **271 tests, 0 failures/cancelled/skipped**. Test mutations mangling option values or labels correctly failed the behavioral tests; no production source was edited for mutation checks.
25
+- The option DOM construction is defense in depth. No exploitable XSS was demonstrated in the previous correctly escaped interpolation; avoid claiming a proven vulnerability.
26
+- Cloudflare reported a failed PR Preview build for `18f663c`; its build log was not available, so the cause remains unverified and separate from Actions billing.
27
+- Recovery procedure: `docs/OPERATIONS_RUNBOOK.md`, “Actions job fails before checkout”. PR #63 remains draft and unmerged. Account owner must resolve GitHub Billing, then obtain fresh CI on the final reviewed head before merge and exact-main CI/deploy/runtime checks afterward. No production deployment or direct-main write was performed in this recovery session.
28
+
29
## Current Architecture
30
- Cloudflare Worker webhook boundary in `src/index.js`.
31
- Telegram coordinator and Safe Approval lifecycle in `src/bot.js`.
docs/OPERATIONS_RUNBOOK.md
+26
@@ -11,6 +11,32 @@
11
## Runtime incident path
12
Treat failed CI/deploy, provider errors, Worker runtime degradation, approval/replay failures, and GitHub/Cloudflare evidence mismatch as explicit failures. Preserve bounded non-secret evidence: exact SHA, workflow/run/job IDs, deployment/version IDs, action ID, outcome and timestamp. Never persist tokens, secret values, source/draft bodies or signed approval callbacks.
13
14
+### Actions job fails before checkout
15
+An empty step list and no runner assignment are not evidence of a test failure. Inspect the job's check annotations before changing code or retrying:
16
+
17
+```bash
18
+gh api repos/davoodmehraban89/nexa-dev-bot/actions/runs/RUN_ID/jobs \
19
+ --jq '.jobs[] | {id, check_run_url, runner_name, steps}'
20
+# Use the check-run ID from check_run_url:
21
+gh api repos/davoodmehraban89/nexa-dev-bot/check-runs/CHECK_RUN_ID/annotations \
22
+ --jq '.[] | {annotation_level, message}'
23
+```
24
+
25
+If the annotation says recent account payments failed or the spending limit needs increasing, the account owner must resolve the payment issue or Actions budget in GitHub **Settings → Billing & licensing** (older UI: **Billing & plans**). Retrying or editing the workflow cannot remove an account billing restriction. Do not change repository visibility, disable required checks, or merge around this gate.
26
+
27
+Development verification can continue on the exact candidate without deployment credentials:
28
+
29
+```bash
30
+git rev-parse HEAD
31
+npx --yes --package=node@22 -c 'node --version && npm test'
32
+# Use an explicit Wrangler version for reproducible local bundling:
33
+npx --yes --package=node@22 --package=wrangler@4.152.0 \
34
+ -c 'wrangler deploy --dry-run --outdir /tmp/nexa-worker-build'
35
+git diff --check
36
+```
37
+
38
+Record the revision, tool versions, full test totals and dry-run result. These are local checks, not GitHub CI, a Preview deployment or production acceptance. After billing is resolved, run CI on the latest reviewed PR head and follow every release gate above. A Cloudflare Preview build failure is a separate incident and requires its own build log; do not assign it the Actions billing cause without evidence.
39
+
40
## Emergency Kill Switch
41
The global Kill Switch has two durable states: `NORMAL` and `LOCKED`. In `LOCKED`, READ remains available for diagnosis, but every WRITE and DESTRUCTIVE action is denied before provider mutation. Automation execution/resume must also pause while locked. If the durable Kill Switch state cannot be read, WRITE/DESTRUCTIVE and Automation fail closed.
42
test/workspace-editor-dom-safety.test.js
+130
-9
@@ -1,18 +1,139 @@
1
import test from 'node:test';
2
import assert from 'node:assert/strict';
3
+import vm from 'node:vm';
4
import { renderWorkspaceEditorPage } from '../src/workspace-editor.js';
5
5
-test('editor creates file options using textContent, never HTML interpolation', () => {
6
- const page = renderWorkspaceEditorPage();
7
- assert.match(page, /document\.createElement\('option'\)/);
8
- assert.match(page, /option\.textContent = file\.path/);
9
- assert.match(page, /option\.value = file\.path/);
10
- assert.match(page, /files\.replaceChildren\(\)/);
11
- assert.doesNotMatch(page, /files\.innerHTML\s*=/);
6
+// These doubles exercise the rendered script's DOM/API boundaries, not HTML parsing.
7
+function element(tagName) {
8
+ const listeners = new Map();
9
+ let value;
10
+ return {
11
+ children: [], textContent: '', className: '', disabled: true,
12
+ get value() {
13
+ if (tagName === 'select') return this.children.find(option => option.value === value)?.value || '';
14
+ return value ?? (tagName === 'option' ? this.textContent : '');
15
+ },
16
+ set value(next) { value = String(next); },
17
+ replaceChildren(...children) { this.children = children; },
18
+ appendChild(child) { this.children.push(child); },
19
+ addEventListener(type, listener) { listeners.set(type, listener); },
20
+ async dispatch(type) {
21
+ assert.ok(listeners.has(type), `missing ${type} listener`);
22
+ await listeners.get(type)();
23
+ }
24
+ };
25
+}
26
+
27
+async function bootEditor(workspace, search = '?workspaceId=W000000001') {
28
+ const elements = Object.fromEntries(['editor', 'status', 'path', 'files', 'counter', 'save', 'close']
29
+ .map(id => [id, element(id === 'files' ? 'select' : id)]));
30
+ const requests = [];
31
+ const location = { search };
32
+ // Both load success and failure display status. Await that observable completion,
33
+ // rather than sleeping or guessing how many promise microtasks need draining.
34
+ let displayStatus;
35
+ const loaded = new Promise(resolve => { displayStatus = resolve; });
36
+ let statusClassName = '';
37
+ Object.defineProperty(elements.status, 'className', {
38
+ get: () => statusClassName,
39
+ set(value) { statusClassName = value; displayStatus(); }
40
+ });
41
+ const script = renderWorkspaceEditorPage().match(/<script>\s*([\s\S]*?)<\/script>/)[1];
42
+ vm.runInNewContext(script, {
43
+ document: { getElementById: id => elements[id], createElement: element },
44
+ window: { Telegram: { WebApp: { initData: 'signed telegram data', ready() {}, expand() {} } } },
45
+ location, URLSearchParams, TextEncoder,
46
+ async fetch(url, options) {
47
+ requests.push({ url, ...JSON.parse(JSON.stringify(options)) });
48
+ return {
49
+ ok: true, status: 200,
50
+ async json() {
51
+ return options.method === 'PUT'
52
+ ? { ok: true, workspace: { id: 'W000000001', path: workspace.path, state: 'DRAFT' } }
53
+ : { workspace, limits: { maxChars: 20000, maxBytes: 65536 } };
54
+ }
55
+ };
56
+ }
57
+ });
58
+ await loaded;
59
+ assert.equal(elements.editor.disabled, false, elements.status.textContent);
60
+ assert.equal(elements.save.disabled, false, elements.status.textContent);
61
+ return { elements, requests, location };
62
+}
63
+
64
+const quoted = 'src/owner\'s "draft" & notes.md';
65
+const entity = 'docs/"&'<.md';
66
+const markup = 'docs/<img src=x onerror=alert(1)>.md';
67
+const unicode = 'docs/راهنما-日本語-🧪.md';
68
+const filenames = [quoted, entity, markup, unicode];
69
+const workspace = {
70
+ id: 'W000000001', path: entity, files: filenames.map(path => ({ path })),
71
+ state: 'DRAFT', baseHeadSha: 'abcdef1234', draftText: '# existing draft\n'
72
+};
73
+
74
+test('editor preserves exact option labels and values for repository-controlled filenames', async () => {
75
+ const { elements, requests } = await bootEditor(workspace,
76
+ '?workspaceId=W000000001&path=docs%2F%26quot%3B%26amp%3B%26%2339%3B%26%23x3C%3B.md');
77
+ assert.equal(elements.files.children.length, 4);
78
+ assert.deepEqual(elements.files.children.map(option => option.textContent), filenames);
79
+ assert.deepEqual(elements.files.children.map(option => option.value), filenames);
80
+ assert.equal(elements.files.value, entity);
81
+ assert.equal(elements.path.textContent, entity);
82
+ assert.equal(elements.editor.value, '# existing draft\n');
83
+ assert.deepEqual(requests, [{
84
+ url: '/workspace/api/editor?workspaceId=W000000001&path=docs%2F%26quot%3B%26amp%3B%26%2339%3B%26%23x3C%3B.md',
85
+ headers: { 'x-telegram-init-data': 'signed telegram data' }
86
+ }]);
87
+});
88
+
89
+test('saving sends the selected literal filename and draft with Telegram authentication', async () => {
90
+ const { elements, requests } = await bootEditor(workspace);
91
+ elements.editor.value = '# edited & <literal> 🧪\n';
92
+ await elements.save.dispatch('click');
93
+ assert.equal(requests.length, 2);
94
+ const saved = requests[1];
95
+ assert.equal(saved.url, '/workspace/api/editor');
96
+ assert.equal(saved.method, 'PUT');
97
+ assert.deepEqual(saved.headers, {
98
+ 'content-type': 'application/json', 'x-telegram-init-data': 'signed telegram data'
99
+ });
100
+ assert.deepEqual(JSON.parse(saved.body), {
101
+ workspaceId: 'W000000001', path: 'docs/"&'<.md', text: '# edited & <literal> 🧪\n'
102
+ });
103
+ assert.equal(elements.status.className, 'status ok');
104
+ assert.equal(elements.save.disabled, false);
105
+});
106
+
107
+test('legacy workspace without a files array exposes its one literal filename', async () => {
108
+ const { elements } = await bootEditor({
109
+ id: 'W000000001', path: 'legacy/" & "draft".md', state: 'DRAFT',
110
+ baseHeadSha: 'abcdef1234', draftText: 'legacy draft'
111
+ });
112
+ assert.equal(elements.files.children.length, 1);
113
+ assert.equal(elements.files.children[0].textContent, 'legacy/" & "draft".md');
114
+ assert.equal(elements.files.children[0].value, 'legacy/" & "draft".md');
115
+ assert.equal(elements.files.value, 'legacy/" & "draft".md');
116
+ assert.equal(elements.editor.value, 'legacy draft');
117
});
118
14
-test('editor page does not embed arbitrary file names in executable markup', () => {
119
+test('changing files preserves special filenames through navigation and the next load', async () => {
120
+ const first = await bootEditor(workspace, '?workspaceId=W000000001&source=telegram');
121
+ for (const filename of filenames) {
122
+ first.elements.files.value = filename;
123
+ await first.elements.files.dispatch('change');
124
+ const params = new URLSearchParams(first.location.search);
125
+ assert.equal(params.get('path'), filename);
126
+ assert.equal(params.get('workspaceId'), 'W000000001');
127
+ assert.equal(params.get('source'), 'telegram');
128
+ const next = await bootEditor({ ...workspace, path: filename }, first.location.search);
129
+ assert.equal(new URL(next.requests[0].url, 'https://example.test').searchParams.get('path'), filename);
130
+ assert.equal(next.elements.files.value, filename);
131
+ assert.equal(next.elements.path.textContent, filename);
132
+ }
133
+});
134
+
135
+test('editor option construction avoids parser-dependent HTML interpolation', () => {
136
const page = renderWorkspaceEditorPage();
16
- assert.match(page, /for \(const file of \(body\.workspace\.files/);
137
+ assert.doesNotMatch(page, /files\.innerHTML\s*=/);
138
assert.doesNotMatch(page, /<option value=['\"][^\n]*file\.path/);
139
});