fix(harvest): wait for cardpen global before use (Release/Pages race) - #402
Merged
Conversation
The harvest pre-generation gate only polled for the static #cpOutput iframe element to exist, not for the `cardpen` global (defined by main.js, the last script on the CardPen page) to be ready. Local IIS (Debug) has ~0 latency so the race is never lost; served from GitHub Pages (Release), CDN latency can let the first `cardpen.form.set` call fire before main.js executed -> "ReferenceError: cardpen is not defined", which blocked release-grade (CMYK/PNG) regeneration. Add an explicit page.WaitForFunctionAsync that cardpen.form and cardpen.write are present before the first use. Defensive and source-agnostic (local IIS or remote Pages). Verified live Pages serves a fully functional CardPen (cardpen object with .form/.write after load; main.js HTTP 200; only console error is a benign favicon 404), so the defect was the harvest load-race, not the Pages content. Build green, 120/0 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problème
Lors d'une régénération Release (CardPen servi depuis GitHub Pages), le harvest plante avec
ReferenceError: cardpen is not defined, ce qui bloque la régén release-grade (CMYK/PNG). En Debug (CardPen servi en local IIS) le pipeline fonctionne.Diagnostic (vérifié, ai-01)
https://argumentumgames.github.io/Argumentum/index.html: après chargement,cardpenest un objet complet (.form+.writeprésents),js/main.jsrépond HTTP 200 et s'exécute entièrement ; la seule erreur console est unfavicon.ico404 bénin.HarvestManager. Le gate amont (HarvestManager.cs:374-393) n'attend que l'existence de l'élément iframe statique#cpOutput(présent dès le parsing du HTML), pas la définition du globalcardpen— défini parmain.js, le dernier script de la page. PuisHarvestManager.cs:483appellecardpen.form.set(...)sans garde d'existence.main.js→ReferenceError. Comportement intermittent cohérent avec un échec de course.Correctif
Ajout d'un
page.WaitForFunctionAsync("() => typeof cardpen !== 'undefined' && cardpen.form && cardpen.write")avant le premier usage decardpen(HarvestManager.cs:483). Défensif, source-agnostique (IIS local ou Pages distant), timeout 120s aligné sur les autres attentes du fichier. Aucune régression de comportement en Debug (où la garde est satisfaite immédiatement).Validation
dotnet build: 0 erreur.dotnet test: 120 réussis / 0 échec / 5 ignorés.cardpen is not defineda disparu sur un run Release complet.Notes
HarvestManager.cs:522,cardpendans le contexte iframe où il n'est pas défini) est déjà protégé par try/catch + fallback DPI — hors scope, non touché.🤖 Generated with Claude Code