"use strict";
/**
 * Copyright: (c) Myia SAS 2026.
 * This file and its contents are licensed under the AGPLv3 License.
 * Please see the LICENSE file at the root of this repository
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.HealTracesLayout = void 0;
// Single source of truth for the persistent on-disk layout the tracer
// produces under `<rootDir>/heal-traces/`:
//
//   <rootDir>/heal-traces/<executionId>/<playwrightTestId>/<attempt>/heal-traces.ndjson
//   <rootDir>/heal-traces/<executionId>/<playwrightTestId>/<attempt>/trace.zip
//   <rootDir>/heal-traces/<executionId>/<playwrightTestId>/<attempt>/screenshots/<file>
//   <rootDir>/heal-traces/<executionId>/<playwrightTestId>/<attempt>/videos/<file>
//
// Pure path joins — no I/O, no fs.existsSync, no validation beyond
// traversal-safety on user-supplied relative paths.
const path = __importStar(require("path"));
class HealTracesLayout {
    constructor(rootDir, executionId) {
        this.rootDir = rootDir;
        this.executionId = executionId;
    }
    healTracesRoot() {
        return path.join(this.rootDir, HealTracesLayout.DIRNAME);
    }
    executionDir() {
        return path.join(this.healTracesRoot(), this.executionId);
    }
    testDir(playwrightTestId, attempt) {
        return path.join(this.executionDir(), playwrightTestId, String(attempt));
    }
    ndjsonPath(playwrightTestId, attempt) {
        return path.join(this.testDir(playwrightTestId, attempt), HealTracesLayout.NDJSON_FILENAME);
    }
    networkNdjsonPath(playwrightTestId, attempt) {
        return path.join(this.testDir(playwrightTestId, attempt), HealTracesLayout.NETWORK_NDJSON_FILENAME);
    }
    consoleNdjsonPath(playwrightTestId, attempt) {
        return path.join(this.testDir(playwrightTestId, attempt), HealTracesLayout.CONSOLE_NDJSON_FILENAME);
    }
    tracePath(playwrightTestId, attempt) {
        return path.join(this.testDir(playwrightTestId, attempt), HealTracesLayout.TRACE_FILENAME);
    }
    screenshotPath(playwrightTestId, attempt, filename) {
        return path.join(this.testDir(playwrightTestId, attempt), HealTracesLayout.SCREENSHOTS_SUBDIR, path.basename(filename));
    }
    videoPath(playwrightTestId, attempt, filename) {
        return path.join(this.testDir(playwrightTestId, attempt), HealTracesLayout.VIDEOS_SUBDIR, path.basename(filename));
    }
    /**
     * Resolve a free-form relative path under the per-attempt directory
     * (used for user attachments where preserving subdirs matters).
     * Throws if `relPath` resolves outside the per-attempt root —
     * guarding against path-traversal in attachment paths.
     */
    attachmentPath(playwrightTestId, attempt, relPath) {
        const root = this.testDir(playwrightTestId, attempt);
        const resolved = path.resolve(root, relPath);
        const rootResolved = path.resolve(root);
        if (resolved !== rootResolved && !resolved.startsWith(rootResolved + path.sep)) {
            throw new Error(`attachment path escapes test directory: ${relPath}`);
        }
        return resolved;
    }
    executionsNdjsonPath() {
        return path.join(this.healTracesRoot(), HealTracesLayout.EXECUTIONS_NDJSON);
    }
    executionManifestPath() {
        return path.join(this.executionDir(), HealTracesLayout.EXECUTION_MANIFEST);
    }
}
exports.HealTracesLayout = HealTracesLayout;
HealTracesLayout.DIRNAME = 'heal-traces';
HealTracesLayout.NDJSON_FILENAME = 'heal-traces.ndjson';
HealTracesLayout.NETWORK_NDJSON_FILENAME = 'heal-network.ndjson';
HealTracesLayout.CONSOLE_NDJSON_FILENAME = 'heal-console.ndjson';
HealTracesLayout.TRACE_FILENAME = 'trace.zip';
HealTracesLayout.SCREENSHOTS_SUBDIR = 'screenshots';
HealTracesLayout.VIDEOS_SUBDIR = 'videos';
HealTracesLayout.EXECUTIONS_NDJSON = 'executions.ndjson';
HealTracesLayout.EXECUTION_MANIFEST = 'execution.json';
