Skip to content

Improvements#69

Open
llambeau wants to merge 9 commits into
masterfrom
improvements-20260402
Open

Improvements#69
llambeau wants to merge 9 commits into
masterfrom
improvements-20260402

Conversation

@llambeau

@llambeau llambeau commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

No description provided.

llambeau and others added 9 commits April 2, 2026 14:28
Fix a bug in JobRunner where RAW mode crashed because updateMetrics()
was called without null checks in the promise resolution/rejection
handlers of #doRun.

Replace broken proxyquire usage in consumer, server, and REST API tests
with direct imports and sinon stubs. Add tests for: runner RAW mode
(7 tests), NodeJSRunner RAW mode (unskip), dispatcher invalidJobExchange
path, dispatcher queue push failures, consumer stop() and multi-config,
and server stop(). Test count goes from 219 passing + 1 failing to
251 passing + 0 failing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Round 2: AmqpQueue operations tested with mocked amqplib and fetch stubs
using sinon sandboxes. Covers _connect (retry logic, event propagation),
_push (serialization, exchanges, headers), _consume (ACK/NACK, invalid
JSON, null messages), _disconnect, _requeue (shovel creation, errors),
_getQueuesInfo (management API, error handling), and deriveManagementUrl.

Round 3: New test files for ConsumerConfig and JobResult. Config edge
cases (malformed YAML, config without schema files). Richer validator
tests (optional fields, nested objects, type coercion). Binary runner
stderr tests changed from skip to pending.

Test count: 309 passing, 0 failing (up from 251).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All core components now accept explicit dependencies instead of reaching
into the Arnavon singleton:

- JobDispatcher: accepts optional registry and queue params
- JobRunner/ensureMetrics: accepts optional registry param
- createApi: accepts optional registry in options
- Server: accepts optional registry and queue, passes to dispatcher/API
- Consumer: accepts optional registry and queue, stores and uses them
- REST API: accepts queue and config through options
- NodeJSRunner: accepts cwd in config instead of using Arnavon.require()

Every parameter defaults to Arnavon.* when not provided, so the CLI path
and all existing tests work unchanged (309 passing, 0 test changes).

Arnavon.cwd() and Arnavon.require() are marked @deprecated.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…Phase 2)

ArnavonConfig.from(options) allows building config from plain TypeScript
objects without YAML or Finitio. Defines TypeScript interfaces for
JobDefinition, ConsumerDefinition, QueueDefinition, and ArnavonOptions.

JobValidator now accepts either a Finitio.System or a plain validator
function (data) => data, enabling Zod/Joi/custom validation.

ConsumerConfig accepts a handler function as alternative to runner
config. FunctionRunner wraps the handler with the same metrics/lifecycle
as other runners.

New exports: ValidatorFn, HandlerFn, ArnavonOptions, JobDefinition,
ConsumerDefinition, QueueDefinition, RunnerDefinition.

321 passing tests (12 new), 0 failing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New ArnavonApp class provides an instance-based API for using Arnavon
as a library:

  const app = new ArnavonApp({ queue: { driver: 'amqp', config: {...} } })
  app.job('send-email', { validate: (d) => schema.parse(d) })
  app.consumer('mailer', { queue: 'emails', handler: async (job) => {...} })
  await app.startApi({ port: 3000 })

Features:
- Fluent API with .job() and .consumer() chaining
- .startApi(), .startConsumer(name), .startAllConsumers()
- .fromYaml(path) convenience for YAML-based config
- Own prometheus registry per instance (no singleton dependency)
- Exported as named export: import { ArnavonApp } from '@quadrabee/arnavon'

CLI commands rewritten to use ArnavonApp.fromYaml() internally, removing
all direct references to the Arnavon singleton from CLI code.

335 passing tests (14 new), 0 failing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…gistry

When using ArnavonApp (which has its own registry and doesn't set the
Arnavon singleton), Consumer._startConsuming() created runners via
JobRunner.factor() without passing a registry. The runner constructor
fell back to Arnavon.registry which was undefined, causing a crash.

Now Consumer passes its registry through factor() → RunnersFactory →
runner constructor.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
NodeJSRunner, BinaryRunner, and FunctionRunner constructors were not
accepting or forwarding the registry parameter to the JobRunner base
class. The factory passed (config, registry) but subclass constructors
only accepted (config), so the registry was silently dropped.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ArnavonApp doesn't set Arnavon.config, so NodeJSRunner's fallback to
Arnavon.cwd() crashed with 'Cannot read properties of undefined'.

Consumer now accepts a cwd parameter and injects it into the runner
config when factoring runners. ArnavonApp passes its cwd through.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@llambeau llambeau force-pushed the improvements-20260402 branch from fb1e75d to e42330b Compare April 2, 2026 14:01
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