From d40b0695b25f31af9729cede5f73a9dd9d7d6469 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Thu, 12 Mar 2026 10:04:38 +1300 Subject: [PATCH] fix(docker-command): useDocker should be passed into the execution engine --- .../src/routes/__tests__/export.test.ts | 12 ++++++++++++ .../src/command.execution.ts | 7 +++---- packages/linzjs-docker-command/src/command.ts | 15 +++++++++++++-- .../execution/__tests__/execute.docker.test.ts | 18 +++++++++++++++++- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/packages/lambda-tiler/src/routes/__tests__/export.test.ts b/packages/lambda-tiler/src/routes/__tests__/export.test.ts index 6904e32e06..13192a2282 100644 --- a/packages/lambda-tiler/src/routes/__tests__/export.test.ts +++ b/packages/lambda-tiler/src/routes/__tests__/export.test.ts @@ -52,4 +52,16 @@ describe('tileset.export', () => { ); assert.equal(res.status, 404); }); + + it('should not error on invalid requests', async (t) => { + t.mock.method(ConfigLoader, 'getDefaultConfig', () => Promise.resolve(config)); + t.mock.method(s3Config, 'getSignedUrl', () => Promise.resolve('https://fake-s3-url.com/tileset.mbtiles')); + + config.put(FakeData.tileSetRaster('aerial')); + + const res = await handler.router.handle( + mockUrlRequest('/v1/export/aerial/WebMercatorQuad.mbtiles', 'get', Api.header), + ); + assert.equal(res.status, 400); + }); }); diff --git a/packages/linzjs-docker-command/src/command.execution.ts b/packages/linzjs-docker-command/src/command.execution.ts index 4de3175456..c46baa7b88 100644 --- a/packages/linzjs-docker-command/src/command.execution.ts +++ b/packages/linzjs-docker-command/src/command.execution.ts @@ -4,7 +4,8 @@ import { ExecutorLocal } from './execution/execute.local.js'; import { CommandExecutionResult } from './execution/execute.result.js'; export interface CommandExecutionOptions { - useDocker: boolean; + /** Should this execution use the container */ + useDocker?: boolean; } export class CommandExecution { @@ -15,9 +16,7 @@ export class CommandExecution { useDocker?: boolean; constructor(cmd: Command, opts?: CommandExecutionOptions) { this.cmd = cmd; - if (opts) { - this.useDocker = opts.useDocker; - } + this.useDocker ??= opts?.useDocker; } get isRunWithDocker(): boolean { diff --git a/packages/linzjs-docker-command/src/command.ts b/packages/linzjs-docker-command/src/command.ts index 033702ebdd..c3e7b3e6a7 100644 --- a/packages/linzjs-docker-command/src/command.ts +++ b/packages/linzjs-docker-command/src/command.ts @@ -1,8 +1,19 @@ import { CommandExecution, CommandExecutionOptions } from './command.execution.js'; export interface CommandOptions { - container: string; + /** + * Container to use + * @example "ghcr.io/linz/basemaps/cli" + */ + container?: string; + /** + * Container tag to use + * @example "v7.0.3" + */ tag?: string; + + /** Should the container be used by default */ + useDocker?: boolean; } export class Command { executable: string; @@ -24,7 +35,7 @@ export class Command { } static create(cmd: string, opts?: CommandOptions): CommandExecution { - return new Command(cmd, opts).create(); + return new Command(cmd, opts).create({ useDocker: opts?.useDocker }); } get containerName(): string { diff --git a/packages/linzjs-docker-command/src/execution/__tests__/execute.docker.test.ts b/packages/linzjs-docker-command/src/execution/__tests__/execute.docker.test.ts index 34a627c332..aa3c371586 100644 --- a/packages/linzjs-docker-command/src/execution/__tests__/execute.docker.test.ts +++ b/packages/linzjs-docker-command/src/execution/__tests__/execute.docker.test.ts @@ -2,7 +2,8 @@ import assert from 'node:assert'; import { describe, it } from 'node:test'; import { Command } from '../../command.js'; -import { toDockerExecution } from '../execute.docker.js'; +import { ExecutorDocker, toDockerExecution } from '../execute.docker.js'; +import { ExecutorLocal } from '../execute.local.js'; describe('DockerExecution', () => { it('should run hello world', () => { @@ -38,4 +39,19 @@ describe('DockerExecution', () => { cmd.env('AWS_ACCESS_KEY'); assert.equal(toDockerExecution(cmd).toCommand(), `docker run --rm --env AWS_ACCESS_KEY ubuntu echo hello world`); }); + + it('should skip docker if useDocker is false', async (t) => { + const runDocker = t.mock.method(ExecutorDocker, 'run'); + const runLocal = t.mock.method(ExecutorLocal, 'run'); + const cmdLocal = Command.create('echo', { container: 'ubuntu', useDocker: false }).arg('hello world'); + const cmdDocker = Command.create('echo', { container: 'ubuntu' }).arg('hello world'); + + await cmdLocal.run(); + assert.equal(runLocal.mock.callCount(), 1); + assert.equal(runDocker.mock.callCount(), 0); + + await cmdDocker.run(); + assert.equal(runLocal.mock.callCount(), 1); + assert.equal(runDocker.mock.callCount(), 1); + }); });