feat: run startup export from scenarios/index.ts automatically on server init#1833
Draft
feat: run startup export from scenarios/index.ts automatically on server init#1833
startup export from scenarios/index.ts automatically on server init#1833Conversation
Copilot
AI
changed the title
[WIP] Add startup scenario function for server initialization
feat: run Apr 11, 2026
startup export from scenarios/index.ts automatically on server init
pmcelhaney
requested changes
Apr 11, 2026
Collaborator
pmcelhaney
left a comment
There was a problem hiding this comment.
The pattern should cover the use of scenarios in general, not just startup.
Contributor
Author
Done in commit 4e22d10. Replaced the narrow "Seed Data on Startup" pattern doc with a broader "Scenario Scripts" pattern (
Updated the patterns index and the REPL feature doc cross-links accordingly. |
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.
Summary
Adds a
startuplifecycle hook to scenario scripts. Exporting a function namedstartupfromscenarios/index.tscauses it to run automatically after modules load, right before the REPL prompt appears — no manual.scenariocommand required. Skipped silently if absent.Also adds a new Scenario Scripts pattern doc covering the full lifecycle of scenario scripts: writing them, running them on demand with
.scenario, thestartupautomatic hook, and delegating to helper functions with extra arguments.Original Prompt
A scenario in index.ts called startup should run when the server initializes, right before the REPL starts. It will be used to seed dummy data.
If the function doesn't exist, skip.
Update the docs.
Also create a new pattern. Note that startup() can call other scenario functions and that is recommended to separate concerns and keep the startup function clean. It will need to pass the $ arg to the other functions.
Note that it can configure the other functions by passing additional arguments, e.g.
addPets($, 20, "dog")
Manual acceptance tests
export const startup: Scenario = ($) => { ... }inscenarios/index.tshas context seeded before the REPL prompt appearsstartupexport starts normally with no error or warningstartupcan delegate to a helper —addPets($, 20, "dog")— and the helper's changes appear in the running contextstartupfunctions are awaited before the REPL startsstartupstub inscenarios/index.tsTasks
src/app.ts: ExportedrunStartupScenario(scenarioRegistry, contextRegistry, config, openApiDocument?)— looks upstartupin theindexmodule, builds anApplyContext({ context, loadContext, route, routes }), and calls it; called insidestart()aftermoduleLoader.load().src/typescript-generator/generate.ts: Updated the scaffoldedscenarios/index.tstemplate to include a documentedstartupstub with JSDoc explaining delegation and extra-args patterns.test/app.test.ts: Five new unit tests covering: called when present, receives correct$, no-op with missing module, no-op whenstartupis not a function, awaits async functions.docs/features/repl.md: Added "Startup scenario" section with basic and delegation examples; updated cross-link to point to the new Scenario Scripts pattern.docs/patterns/scenario-scripts.md: New broad pattern doc — "Scenario Scripts" — covering writing scenarios, running them with.scenario(including path-resolution table), thestartupautomatic hook, and the helper-delegation pattern with extra arguments.docs/patterns/index.md: Replaced the narrow "Seed Data on Startup" entry with "Scenario Scripts" in both the prose and the pattern table.