// engine/data-projects-gc/pattern-matcher.ts — SPEC-581
// Pure functions for detecting test/ephemeral project path basenames.
/**
 * Patterns that identify ephemeral / test project directories.
 * Matched case-insensitively against the basename of the project path.
 */
const TEST_PREFIX_RE = /^(test|proj|e2e|demo|example|mock|temp)-/i;
const TEST_INFIX_RE = /(test-|e2e-)/i;
/**
 * Planu-internal test fixtures generated by the test suite. Pattern covers
 * names like `planu-list-specs-read-only-XXX`, `planu-integration-XXX`,
 * `planu-e2e-fixture-XXX`, `planu-spec-helpers-XXX`.
 */
const PLANU_TEST_BASENAME_RE = /^planu-.*-(test|spec|e2e|integration|fixture|list-specs|read-only)-/i;
/**
 * Filesystem prefixes that always denote ephemeral OS-managed temp dirs.
 * Anything created under these is a test fixture, never a productive project.
 * `/private/var/folders` must precede `/var/folders` because macOS exposes
 * both paths for the same physical directory.
 */
const EPHEMERAL_PATH_PREFIXES = [
    '/private/var/folders/',
    '/var/folders/',
    '/tmp/',
    '/private/tmp/',
];
/**
 * Returns true when the given basename looks like a test or ephemeral project
 * that should NOT be persisted to data/projects/.
 *
 * @param basename - The last segment of the project path (e.g. "test-health-score-123").
 */
export function isTestProjectBasename(basename) {
    if (TEST_PREFIX_RE.test(basename)) {
        return true;
    }
    if (TEST_INFIX_RE.test(basename)) {
        return true;
    }
    if (PLANU_TEST_BASENAME_RE.test(basename)) {
        return true;
    }
    return false;
}
/**
 * Returns true when the absolute path lives under an OS-managed temp prefix
 * (`/var/folders`, `/tmp`, etc.). These are always ephemeral regardless of the
 * basename pattern.
 */
export function isEphemeralPathPrefix(projectPath) {
    const normalized = projectPath.replace(/\\/g, '/');
    return EPHEMERAL_PATH_PREFIXES.some((prefix) => normalized.startsWith(prefix));
}
/**
 * Returns true when the full project path is ephemeral and should not be
 * persisted. Combines basename heuristics with absolute-path prefix checks.
 *
 * @param projectPath - Full absolute path to the project (e.g. "/tmp/test-foo").
 */
export function isEphemeralProject(projectPath) {
    if (isEphemeralPathPrefix(projectPath)) {
        return true;
    }
    const parts = projectPath.replace(/\\/g, '/').split('/').filter(Boolean);
    const basename = parts[parts.length - 1] ?? '';
    return isTestProjectBasename(basename);
}
//# sourceMappingURL=pattern-matcher.js.map