Files
qwen-code/scripts/flyway-migration-utils.js
T
jinyeandQwen-Coder f3af3dd857 refactor(managed-agent): Split server into Maven modules (#15871)
* refactor(managed-agent): split server into Maven modules

Separate contracts, orchestration, persistence, adapters, assembly, and verification while retaining the existing service delivery model. Move tests and build consumers together and document local evidence and pending CI acceptance.

Co-authored-by: Qwen-Coder <[email protected]>

* refactor(managed-agent): reduce configuration and SDK boilerplate

Co-authored-by: Qwen-Coder <[email protected]>

* refactor(managed-agent): narrow contracts and simplify test scaffolding

Co-authored-by: Qwen-Coder <[email protected]>

* fix(managed-agent): repair verification after module migration

Resolve shared fixtures and worker paths from the Maven module root, update CI packaging assertions, and align existing test fixtures with the extracted contracts. Restore restricted Workspace constructors and remove redundant test visibility changes without altering inherited MySQL coverage.

Co-authored-by: Qwen-Coder <[email protected]>

* test(managed-agent): align remaining Harness and OSS fixtures

Preserve SDK refusal messages and register the managed OSS adapter at fixture injection points. Keep the existing retry and client shutdown assertions intact.

Co-authored-by: Qwen-Coder <[email protected]>

* style(managed-agent): order Hosted cleanup Harness imports

Co-authored-by: Qwen-Coder <[email protected]>

* test(managed-agent): fix recovery smoke fixture and import order

Supply the required transcript coverage in the recovery browser fixture and wait for history before testing a complete handoff. Preserve its existing safety and submission assertions. Order the cleanup coordinator test imports for Checkstyle.

Co-authored-by: Qwen-Coder <[email protected]>

---------

Co-authored-by: Qwen-Coder <[email protected]>
2026-10-30 14:56:35 +00:00

73 lines
2.7 KiB
JavaScript

/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
// Flyway's naming rules for managed-agent-server's hand-allocated versions,
// shared by check-flyway-migrations.js (one checkout) and
// check-flyway-open-prs.js (open pull requests against main).
import { existsSync, readdirSync } from 'node:fs';
import path from 'node:path';
// Registered locations cover the legacy upgrades and the fresh managed-schema
// baseline in Managed Agent Server; versions are checked across dependencies.
// Flyway scans each location AND its subdirectories, and nowhere else — a
// versioned-migration file anywhere
// else under the source root is invisible to it, so finding one there means
// the location moved and check-flyway-migrations.js must say so instead of
// passing on what is left. Its probes derive the db roots and source roots
// from this table, so editing it cannot silently blind them.
export const LOCATIONS = [
{
dir: ['persistence', 'src', 'main', 'resources', 'db', 'migration'],
suffix: '.sql',
},
{
dir: ['persistence', 'src', 'main', 'java', 'db', 'migration'],
suffix: '.java',
},
{
dir: ['persistence', 'src', 'main', 'resources', 'db', 'managed-schema'],
suffix: '.sql',
},
{ dir: ['src', 'main', 'resources', 'db', 'migration'], suffix: '.sql' },
{ dir: ['src', 'main', 'java', 'db', 'migration'], suffix: '.java' },
{ dir: ['src', 'main', 'resources', 'db', 'managed-schema'], suffix: '.sql' },
];
// A versioned migration is V<version>__<description>; the version is numeric
// segments joined by dots or underscores.
const MIGRATION_NAME = /^V(\d+(?:[._]\d+)*)__/;
// Flyway compares versions numerically segment by segment, so V016 collides
// with V16 and a trailing .0 segment carries no meaning.
const normalize = (version) =>
version
.split(/[._]/)
.map((segment) => segment.replace(/^0+(?=\d)/, ''))
.join('.')
.replace(/(\.0)*$/, '');
export const migrationVersion = (name) =>
normalize(MIGRATION_NAME.exec(name)[1]);
// Flyway matches the suffix case-insensitively — V1__b.SQL claims version 1
// exactly like V1__a.sql does.
export const isMigrationFile = (name, suffix) =>
name.toLowerCase().endsWith(suffix) && MIGRATION_NAME.test(name);
// Not readdirSync's `recursive`: a Node older than 18.17 ignores it (see
// check-failsafe-reports.js). Flyway scans a location's subdirectories too.
export const migrationFiles = (dir, suffix) => {
if (!existsSync(dir)) return [];
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) =>
entry.isDirectory()
? migrationFiles(path.join(dir, entry.name), suffix)
: isMigrationFile(entry.name, suffix)
? [path.join(dir, entry.name)]
: [],
);
};