Skip to content

fix: resolve hardcoded logic entry point in TemplateArchiveProcessor#108

Open
Sup-ri-tha wants to merge 2 commits intoaccordproject:mainfrom
Sup-ri-tha:Sup-ri-tha/i107/fix-hardcoded-logic-entrypoint
Open

fix: resolve hardcoded logic entry point in TemplateArchiveProcessor#108
Sup-ri-tha wants to merge 2 commits intoaccordproject:mainfrom
Sup-ri-tha:Sup-ri-tha/i107/fix-hardcoded-logic-entrypoint

Conversation

@Sup-ri-tha
Copy link

@Sup-ri-tha Sup-ri-tha commented Mar 14, 2026

Summary

Fixes #107 by dynamically resolving the logic entry point in TemplateArchiveProcessor, eliminating the hardcoded logic/logic.ts assumption noted by the // TODO DCS comment.

Problem

When trigger() and init() look up compiled code, they hardcode compiledCode['logic/logic.ts'].code. This fails in two ways - if the logic file has any other name, compiledCode['logic/logic.ts'] returns undefined causing a crash. Additionally, compiledCode contains non-TypeScript files like logic/README.md whose invalid compiled output causes btoa() in JavaScriptEvaluator to throw SyntaxError: Invalid or unexpected token.

Solution

Added a dynamic entry point lookup that searches for a .ts file directly in logic/ that is not auto-generated and has valid compiled output, replacing the hardcoded string in both methods.

Changes

  • src/TemplateArchiveProcessor.ts: Replace hardcoded logic/logic.ts with dynamic entry point lookup in both trigger() and init()

Testing

  • All existing tests pass
  • Fix correctly resolves logic/logic.ts as entry point for existing test archive

Checklist

  • Code follows project conventions
  • All tests pass
  • DCO sign-off included

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and init() to replace compiledCode['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.

Comment on lines +114 to +118
const entryPoint = Object.keys(compiledCode).find(
key => key.startsWith('logic/') &&
!key.includes('generated/') &&
key.endsWith('.ts') &&
compiledCode[key].code !== undefined
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added a path depth check to restrict matches to direct children of logic/ only. It prevents nested files from being picked up accidentally.

Comment on lines +115 to +118
key => key.startsWith('logic/') &&
!key.includes('generated/') &&
key.endsWith('.ts') &&
compiledCode[key].code !== undefined
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped this. noErrorValidation: true is already set in the compiler options and the errors array isn't reliably populated in all cases. Felt like it could cause more problems than it solves. Let me know if you would still like this in.

Comment on lines +114 to +122
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');
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Extracted it into a shared private helper method, called from both trigger() and init().

Comment on lines +114 to +128
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,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +114 to +121
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');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped this as well. Listing internal file paths in errors felt like it could confuse template authors more than help. Happy to revisit if you think it's worth adding!

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>
@Sup-ri-tha Sup-ri-tha force-pushed the Sup-ri-tha/i107/fix-hardcoded-logic-entrypoint branch from 23bf01c to 09597be Compare March 15, 2026 15:08
@Sup-ri-tha
Copy link
Author

Hi @dselman @mttrbrts , I've gone through the review comments and addressed them. Would really appreciate a review when you get the time..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix hardcoded logic entry point in TemplateArchiveProcessor

2 participants