Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Tidy DemoService (move inline bot source into samples)

Open Beginner friendly
#146 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Domain
backend

Research direction

Read server/src/services/DemoService.ts and the sample files in ui/public/samples; compare the existing runtime file-reading pattern in server/src/api/mcp.ts. Move the demo source into a sample file and have DemoService load it. Run server/test/sampleBots.test.ts; done means the demo reuses the sample source and the sample smoke test passes.

Written by the indexing model from the issue text.

Description

good first issue priority: low tech-debt

Move DemoService's inline hardcoded bot source into ui/public/samples and reuse it.

Effort: S


Migrated from TASKS.md (Later / nice to have).

Implementation notes

Priority: low — Pure internal code-tidiness refactor of the demo endpoint's hardcoded source with no user-facing behavior change and no stability/security impact.

Purpose

DemoService.getDemoEnvironment (server/src/services/DemoService.ts:19-58) hardcodes ~40 lines of bot source as a template literal set via app1.setSource(...). Moving it into ui/public/samples/*.js (already the single source of truth for sample bots, consumed by the UI's /samples/:name viewer and the MCP robocodejs://samples/{name} resource) removes duplicated/drifting bot logic from server code, keeps demo behavior editable without a server rebuild, and gets it covered by the existing sample-bot smoke test for free.

Implementation approach
  • Add the demo's logic as a new file, e.g. ui/public/samples/demo.js (or patrol.js/similar), following the header-comment + Event.START/clock.on(Event.TICK, ...) style already used by firstbot.js, survivor.js, etc. — clean up the raw Math.random() edge-avoidance into the same idiomatic patterns (bot.radar.onReady().then(bot.radar.scan), .catch(() => {})) other samples use.
  • In server/src/services/DemoService.ts, replace the inline template literal with a file read, mirroring the existing runtime-read pattern in server/src/api/mcp.ts (PUBLIC_DIR = path.join(__dirname, '../../public'), readPublic('samples', filename) guarded by PUBLIC_SUBDIRS) rather than re-deriving a new path scheme — consider extracting readPublic/PUBLIC_DIR out of mcp.ts into a small shared util (e.g. util/publicFiles.ts) since both call sites need it.
  • No compiler.ts / bot-API surface changes — this is pure content relocation, not a new bot capability.
  • No UI or Simulation changes required; ui/src/util/simulate.ts and server/src/util/simulation.ts are unaffected.
Key details to plan
  • No DB/schema changes; DemoService still calls app1.setSource(...), just with file content instead of a literal — unaffected by the no-migrations gap (#142).
  • No REST/MCP contract changes (/api/demo/* endpoints unchanged).
  • Sandbox/security: none — same trusted, server-authored source, just relocated.
  • Testing: extend/rely on server/test/sampleBots.test.ts, which already fs.readdirSyncs ui/public/samples and drives every file through a real isolate + Simulation.run — the new file is automatically covered. Optionally add a small DemoService test asserting setSource receives non-empty content read from disk (mock fs).
  • Determinism/SSE/reducer: unaffected.
  • Dependencies: none blocking; loosely related to the terminology-app-vs-bot.md sweep (samples still use bot-era naming) but not required for this issue.
  • Effort/risk: matches the S estimate — low risk, mechanical refactor, guarded by an existing test file.
Dominant language
TypeScript
Stars
0
Forks
0
Avg merge
8m
Merged PRs (30d)
8

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LeeAdcock/robocodeJs.com

All issues in LeeAdcock/robocodeJs.com

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.