fix(site-builder): swap build-stamp console.log for a window global, add test

Review found two real issues in the initial build-stamp commit:

- A permanent, unconditional console.log on every editor load for every
  customer is production noise. Replaced with a window.__WHP_EDITOR_BUILD__
  assignment -- same load-bearing effect (keeps build-stamp.ts from being
  tree-shaken out before Task 19 wires in the real call site), but prints
  nothing. Support can ask a user to type __WHP_EDITOR_BUILD__ in the
  console on request. Commented as load-bearing so it isn't later "cleaned
  up" as a stray global.
- editorBuild()'s 'dev' fallback was never actually exercised by any test
  in the suite, despite the previous report claiming otherwise. Added
  build-stamp.test.ts asserting editorBuild() === 'dev' under vitest.

Also silences the expected-failure stderr git prints on the successful
'nogit' fallback path (stdio: ['ignore', 'pipe', 'ignore']), so a
release-tarball build log doesn't show a misleading fatal: line for an
intentional, handled case.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-09 11:05:01 -07:00
co-authored by Claude Opus 5
parent 024f9fdd46
commit 4cfcccd272
3 changed files with 21 additions and 6 deletions
+9 -5
View File
@@ -10,11 +10,15 @@ import './styles/editor.css';
// captured too. // captured too.
installConsoleErrorBuffer(); installConsoleErrorBuffer();
// Logged so the build that produced a given session is visible in the // Exposed on window (not logged -- no need to print this on every load for
// browser console; also the only current reference to `editorBuild()`, // every customer) so support can ask someone to type __WHP_EDITOR_BUILD__
// which keeps the __EDITOR_BUILD__-reading module from being tree-shaken // in the console on request. This call is also load-bearing for bundling:
// out of the bundle before Task 19 wires it into the report payload. // it is currently the only reference to `editorBuild()`, which keeps the
console.log(`[site-builder] build ${editorBuild()}`); // __EDITOR_BUILD__-reading module from being tree-shaken out of the bundle
// before Task 19 wires it into the report payload. Do not remove this line
// as a "stray global" cleanup -- doing so silently reverts every future
// bug report to showing 'dev' instead of a real build stamp.
(window as any).__WHP_EDITOR_BUILD__ = editorBuild();
// Read WHP_CONFIG injected by PHP wrapper (or null for standalone dev) // Read WHP_CONFIG injected by PHP wrapper (or null for standalone dev)
const whpConfig: WhpConfig | null = (window as any).WHP_CONFIG || null; const whpConfig: WhpConfig | null = (window as any).WHP_CONFIG || null;
+8
View File
@@ -0,0 +1,8 @@
import { describe, it, expect } from 'vitest';
import { editorBuild } from './build-stamp';
describe('editorBuild', () => {
it("returns 'dev' when __EDITOR_BUILD__ is undefined (vitest does not apply Vite's define)", () => {
expect(editorBuild()).toBe('dev');
});
});
+4 -1
View File
@@ -9,7 +9,10 @@ import { execSync } from 'child_process'
const editorBuild = (() => { const editorBuild = (() => {
let sha = 'nogit' let sha = 'nogit'
try { try {
sha = execSync('git rev-parse --short HEAD', { cwd: __dirname }).toString().trim() sha = execSync('git rev-parse --short HEAD', {
cwd: __dirname,
stdio: ['ignore', 'pipe', 'ignore'],
}).toString().trim()
} catch { } catch {
// Building outside a git checkout (release tarball) -- keep 'nogit'. // Building outside a git checkout (release tarball) -- keep 'nogit'.
} }