Files
memind/scripts/goosed-harness-mysql2-cli.test.mjs
T
john afeafa1d57 fix(goosed-ops): ship mysql2 CLI shim for harness memory on native pool
The 103 harness shim imported mysql2 from a Docker-only path, so every
harness_remember failed on the native pool. The shim resolves mysql2 from
the Portal runtime (or MEMIND_MYSQL2_MODULE) and ships in the runtime.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-23 14:25:24 +08:00

44 lines
1.6 KiB
JavaScript

import assert from 'node:assert/strict';
import { test } from 'node:test';
import {
findLastRowSet,
formatRows,
parseArgs,
resolveMysql2Module,
} from './goosed-harness-mysql2-cli.mjs';
test('parseArgs reads the mysql CLI subset harness uses', () => {
assert.deepEqual(
parseArgs(['-h', 'db.local', '-u', 'boot', '--default-character-set=utf8mb4', '--batch', '-N', 'codex_harness', '-e', 'SELECT 1']),
{ host: 'db.local', user: 'boot', database: 'codex_harness', sql: 'SELECT 1', noHeaders: true },
);
});
test('resolveMysql2Module resolves from the Memind node_modules, not /opt/portal', () => {
const resolved = resolveMysql2Module({});
assert.match(resolved, /node_modules[\\/]mysql2[\\/]promise\.js$/);
assert.doesNotMatch(resolved, /^\/opt\/portal/);
});
test('resolveMysql2Module honours MEMIND_MYSQL2_MODULE override', () => {
assert.equal(resolveMysql2Module({ MEMIND_MYSQL2_MODULE: '/x/promise.js' }), '/x/promise.js');
});
test('findLastRowSet returns a single SELECT row set as-is', () => {
const rows = [['1', 'a'], ['2', null]];
assert.equal(findLastRowSet(rows), rows);
assert.equal(formatRows(findLastRowSet(rows)), '1\ta\n2\tNULL\n');
});
test('findLastRowSet skips ResultSetHeader in multi-statement results', () => {
const header = { affectedRows: 1, insertId: 7 };
const rows = [['7']];
assert.equal(findLastRowSet([header, rows]), rows);
assert.equal(formatRows(findLastRowSet([header, rows])), '7\n');
});
test('findLastRowSet returns null for DDL-only results', () => {
assert.equal(findLastRowSet({ affectedRows: 0 }), null);
assert.equal(formatRows(findLastRowSet({ affectedRows: 0 })), '');
});