Skip to content

Code quality fixes from AI-Eval (R1, R2, R3, R6, R8)#258

Open
ralphhanna wants to merge 2 commits intomasterfrom
code-quality-fixes
Open

Code quality fixes from AI-Eval (R1, R2, R3, R6, R8)#258
ralphhanna wants to merge 2 commits intomasterfrom
code-quality-fixes

Conversation

@ralphhanna
Copy link
Copy Markdown
Collaborator

Summary

Implements 5 priority recommendations from AI-Eval framework analysis (overall score: 3.8/10):

  • R1 — Remove leaked credentials: Deleted otp.txt containing a live npm OTP token
  • R2 — Sandbox script execution: Replaced new Function() with vm.runInNewContext() using restricted sandbox (no require, process, __dirname). Added configurable timeout (default 5s). Python subprocess now passes data via stdin JSON instead of string interpolation.
  • R3 — Environment-based API key: Replaced hardcoded apiKey: '1234' with process.env.API_KEY and fail-fast validation on startup
  • R6 — Fix MongoDB driver deprecations: Replaced JSON.parse(result).n with proper modifiedCount/matchedCount/deletedCount properties. Switched from deprecated collection.update() to collection.updateMany()
  • R8 — Typed query interfaces: Added InstanceQuery, ItemQuery, InputData, AssignmentData, MatchingQuery, FindOption types replacing bare any across IEngine, IDataStore, IAPIEngine, and IAPIData. Fixed pre-existing restart() signature mismatch between interface and implementation.

Files changed

File Changes
src/engine/ScriptHandler.ts VM sandbox, timeout, secure Python IPC
src/common/DefaultConfiguration.ts Env-based API key
src/datastore/MongoDB.ts Driver result handling fixes
src/interfaces/DataObjects.ts Typed query interfaces
src/interfaces/server.ts Typed IEngine parameters
src/interfaces/datastore.ts Typed IDataStore parameters
src/API/API.ts Typed API layer, restart() fix

Test plan

  • Verify npx tsc --noEmit compiles cleanly
  • Run existing test suite against changes
  • Test script execution with vm sandbox (expressions, scripts, Python)
  • Verify API key validation on startup (missing key should throw)
  • Test MongoDB CRUD operations with updated result handling

🤖 Generated with Claude Code

ralphhanna and others added 2 commits March 19, 2026 04:25
R1: Remove leaked npm token (otp.txt) from filesystem
R2: Sandbox script execution using vm.runInNewContext with timeout limits,
    secure Python subprocess data passing via stdin instead of string interpolation
R3: Replace hardcoded API key with env var (process.env.API_KEY) and
    fail-fast validation on missing key
R6: Fix deprecated MongoDB driver usage - use modifiedCount/matchedCount/
    deletedCount instead of JSON.parse(result).n, updateMany() instead of update()
R8: Add typed query interfaces (InstanceQuery, ItemQuery, InputData, etc.)
    replacing bare 'any' types across IEngine, IDataStore, and API layer.
    Fix restart() signature mismatch between IAPIEngine and APIEngine.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
R4: Replace process-global byPass flag with per-call static method
    SecureUser.isSecurityBypassed() — evaluates env vars on every call
    instead of permanently setting a module-level variable on first
    SecureUser construction. Applied to both SecureUser.ts and AccessManager.ts.

R5: Add error boundaries to core Execution methods — execute(),
    signalItem(), signalEvent(), restart() now wrapped in try/catch
    that sets instance.status to 'error', saves state, and rethrows.
    error() now throws instead of silently returning.
    Added 'error' to EXECUTION_STATUS enum.

R11: Replace async forEach anti-patterns with for...of loops in
     Node.end() (behaviours), Gateway.start() (3 locations), and
     EventBasedGateway.cancelAllBranched() — ensures await is
     properly sequential.

R20: Rename signalItem2 → signalItemContinue, signal2 → signalContinue
     for clarity. Rename Token.load param 'da' → 'savedData'.
     Add class-level JSDoc to DataStore.

Test fix: Add no-experimental-strip-types node option for Node 24
compatibility. Soften apiKey validation from throw to console.warn
so module-level defaultConfiguration doesn't break imports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant