fix: resolve hardcoded logic entry point in TemplateArchiveProcessor#108
fix: resolve hardcoded logic entry point in TemplateArchiveProcessor#108Sup-ri-tha wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Resolves #107 by removing the hardcoded logic/logic.ts lookup in TemplateArchiveProcessor and instead selecting a logic entry point from the compiled script set so templates with different logic filenames (and non-TS files in logic/) don’t crash.
Changes:
- Add runtime logic entry point discovery for both
trigger()andinit()to replacecompiledCode['logic/logic.ts']. - Add a clearer failure mode when no entry point is found.
- Update
package-lock.json(appears unrelated to the functional change).
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/TemplateArchiveProcessor.ts | Replaces hardcoded logic module path with a discovered entry point for evaluation in trigger() and init(). |
| package-lock.json | Removes multiple "peer": true fields from various dependency entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| const entryPoint = Object.keys(compiledCode).find( | ||
| key => key.startsWith('logic/') && | ||
| !key.includes('generated/') && | ||
| key.endsWith('.ts') && | ||
| compiledCode[key].code !== undefined | ||
| ); | ||
| if(!entryPoint) { | ||
| throw new Error('Could not find compiled logic entry point'); | ||
| } | ||
| const evaluator = new JavaScriptEvaluator(); | ||
| const evalResponse = await evaluator.evalDangerously( { | ||
| templateLogic: true, | ||
| verbose: false, | ||
| functionName: 'trigger', | ||
| code: compiledCode['logic/logic.ts'].code, // TODO DCS - how to find the code to run? | ||
| code: compiledCode[entryPoint].code, |
There was a problem hiding this comment.
Added 3 unit tests covering: non-standard filenames, exclusion of generated and non-ts files, and the missing entry point case. Initially tried full end-to-end tests but hit a pre-existing twoslash limitation where the compiler crashes on a second invocation in the same Jest process. Unit tests felt like the cleaner solution here.
Both trigger() and init() methods hardcoded 'logic/logic.ts' as the logic entry point when looking up compiled code. This caused a crash if the logic file had any other name. Dynamically find the entry point by searching for a .ts file directly in the logic/ folder that is not auto-generated and has compiled output. Fixes accordproject#107 Signed-off-by: Supritha Rajashekar <supritharajashekar10@gmail.com>
Signed-off-by: Supritha Rajashekar <supritharajashekar10@gmail.com>
23bf01c to
09597be
Compare
|
Thanks for this contribution! Before we can review, please resolve the merge conflicts with the base branch. git fetch origin main
git rebase origin/main
# Resolve conflicts
git push --force-with-leaseOnce the conflicts are resolved, we'll proceed with the review. This comment was generated by AI on behalf of @mttrbrts. |
|
@copilot resolve the merge conflicts in this pull request |
There was a problem hiding this comment.
Thanks @Sup-ri-tha — the crash you're fixing is real, and the test fixture with a non-standard filename is a nice reproduction.
One concern before we merge: the resolver silently picks the first .ts file it finds via Object.keys(compiledCode).find(...). Today there's only ever one candidate, so this works — but it quietly commits us to "first-found wins" as the policy, which becomes a footgun when we start supporting multiple logic files. Two archives with the same files could resolve to different entry points depending on iteration order, and the bug would be silent. We have a WIP PR here for multi-file support, #150
Could you make two small tweaks?
- Throw when more than one candidate is found, rather than silently picking one. Something like:
const candidates = Object.keys(compiledCode).filter(/* same predicate */);
if (candidates.length === 0) {
throw new Error('Could not find compiled logic entry point');
}
if (candidates.length > 1) {
throw new Error(`Ambiguous logic entry point: found ${candidates.join(', ')}. Only one .ts file is currently supported at the top of logic/.`);
}
const entryPoint = candidates[0];
That preserves the single-entry-point assumption explicitly and turns the future multi-file case into a loud failure instead of a silently-wrong result.
- Keep a TODO comment (or open a follow-up issue and reference it) noting that proper multi-file support will need a real convention — e.g. a main field in package.json, function-name-based resolution (find the file exporting trigger/init), or a required filename. The original // TODO DCS was a useful signal that this needs design, and I'd rather not lose it.
With those changes I'm happy to merge. Thanks again!
Summary
Fixes #107 by dynamically resolving the logic entry point in
TemplateArchiveProcessor, eliminating the hardcodedlogic/logic.tsassumption noted by the// TODO DCScomment.Problem
When
trigger()andinit()look up compiled code, they hardcodecompiledCode['logic/logic.ts'].code. This fails in two ways - if the logic file has any other name,compiledCode['logic/logic.ts']returnsundefinedcausing a crash. Additionally,compiledCodecontains non-TypeScript files likelogic/README.mdwhose invalid compiled output causesbtoa()inJavaScriptEvaluatorto throwSyntaxError: Invalid or unexpected token.Solution
Added a dynamic entry point lookup that searches for a
.tsfile directly inlogic/that is not auto-generated and has valid compiled output, replacing the hardcoded string in both methods.Changes
src/TemplateArchiveProcessor.ts: Replace hardcodedlogic/logic.tswith dynamic entry point lookup in bothtrigger()andinit()Testing
logic/logic.tsas entry point for existing test archiveChecklist