Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): gate bare port: fallback to no-explicit-source; document collision reject
Adam Eivy41b01826ef95
diff --git a/server/services/streamingDetect.js b/server/services/streamingDetect.jsindex 1574d596e5..98ef8b5c22 100644--- a/server/services/streamingDetect.js+++ b/server/services/streamingDetect.js@@ -611,10 +611,17 @@ function rewriteLabelInBlock(block, label, oldP, newP) {if (label === 'api') {if (hasInlinePortsObj) portsObjPats.push(`(\\bapi\\s*:\\s*)${NUM}`); // ports: { api: N }if (!hasPortsReference) {+ // The env `PORT` (and its `|| N` fallback) mirror the runtime API port,+ // so they move WITH an inline ports object — fine to rewrite either way.blockPats.push(`(${PORT_KEY}[^,}\\n]*?\\|\\|\\s*['"]?)${NUM}`); // PORT: … || N (fallback)blockPats.push(`(${PORT_KEY})${NUM}`); // env PORT: N- blockPats.push(`(\\bport\\s*:\\s*)${NUM}`); // port: N}+ // A bare lowercase `port:` is parseEcosystemConfig's LAST-RESORT derivation+ // (`directPortMatch`), consulted only when there's no ports object/env. So+ // rewrite it ONLY when there's no explicit ports source — otherwise it'd+ // hit an unrelated same-valued field (e.g. `metadata: { port: 6000 }`) the+ // parser never read as the API port.+ if (!hasExplicitPortsSource) blockPats.push(`(\\bport\\s*:\\s*)${NUM}`); // port: N} else {const hasDevUiKey = /\bdevUi\s*:\s*\d/.test(block);if (hasInlinePortsObj) {@@ -919,6 +926,11 @@ export async function writeEcosystemPortEdits(repoPath, remap, edits) {const forwardCollision = hasRemap && hasEdits && targetedOlds.some(o => remapNews.includes(o));const reverseCollision = hasRemap && hasEdits && remapOlds.some(o => targetedNews.includes(o));+ // Both directions collide ⇒ neither single ordering is safe (a true value+ // cycle, e.g. swapping ui↔devUi between two same-block ports). Resolving it+ // would need per-edit placeholder staging; that's an exotic intra-block port+ // swap well outside the shared/derived cases this path targets, so we+ // conservatively reject (a safe 422 — no corruption) rather than build it.if (forwardCollision && reverseCollision) {return { file: name, changed: false, remapApplied: false, applied: [], unapplied: edits || [] };}diff --git a/server/services/streamingDetect.test.js b/server/services/streamingDetect.test.jsindex 15aedf7ea4..5035884f5f 100644--- a/server/services/streamingDetect.test.js+++ b/server/services/streamingDetect.test.js@@ -560,6 +560,31 @@ module.exports = { apps: [expect(parseEcosystemConfig(r.content).processes[0].ports.api).toBe(7000);});+ it('does not rewrite a bare lowercase port: field when an inline ports object is the source', () => {+ // parseEcosystemConfig reads ports.api and ignores `metadata.port`; the bare+ // `port:` fallback is last-resort (only when there's no ports object), so it+ // must NOT fire here and corrupt the unrelated same-valued metadata field.+ const content = `module.exports = { apps: [+ { name: 'srv', script: 's.js', ports: { api: 6000, ui: 5556 }, metadata: { port: 6000 } }+] };+`;+ const r = rewriteEcosystemPortsByProcess(content, [+ { processName: 'srv', label: 'api', oldPort: 6000, newPort: 7000 },+ ]);+ expect(r.applied).toHaveLength(1);+ expect(r.content).toContain('api: 7000');+ expect(r.content).toContain('metadata: { port: 6000 }'); // untouched+ });++ it('still rewrites a bare legacy port: field when it is the only source (no ports object)', () => {+ const content = `module.exports = { apps: [{ name: 'srv', script: 's.js', port: 6000 }] };`;+ const r = rewriteEcosystemPortsByProcess(content, [+ { processName: 'srv', label: 'api', oldPort: 6000, newPort: 7000 },+ ]);+ expect(r.applied).toHaveLength(1);+ expect(r.content).toContain('port: 7000');+ });+it('does NOT match a same-valued lowercase metadata field in a ports-reference block (no false api success)', () => {// api is derived from `ports: PORTS.server` (external const). The block also// carries a lowercase metadata field that happens to share the value. An