"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
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlaywrightTestContextAdapter = void 0;
const heal_tag_prefix_1 = require("./heal-tag-prefix");
class PlaywrightTestContextAdapter {
    constructor(hooks, options) {
        this.hooks = hooks;
        this.options = options;
    }
    capture(testInfo) {
        const attempt = testInfo.retry + 1;
        const rawTagSuffix = testInfo.tags.find((t) => t.startsWith(heal_tag_prefix_1.HEAL_TAG_PREFIX))?.slice(heal_tag_prefix_1.HEAL_TAG_PREFIX.length) ?? '';
        // Only digits allowed — the backend schema stores testCaseId as
        // bigint. Anything else (empty, letters, negative, leading zeros
        // parsed to 0) is treated as "no id" so the run goes to the
        // unlinked bucket instead of silently mis-linking.
        const testCaseId = /^[1-9]\d*$/.test(rawTagSuffix)
            ? Number.parseInt(rawTagSuffix, 10)
            : undefined;
        const executionId = this.options.resolveExecutionId();
        this.hooks.setContext({
            workerIndex: testInfo.workerIndex,
            parallelIndex: testInfo.parallelIndex,
            testId: testInfo.testId,
            testTitle: testInfo.title,
            titlePath: testInfo.titlePath,
            projectName: testInfo.project.name,
            testFile: testInfo.file,
            retry: testInfo.retry,
            attempt,
            executionId,
            ...(testCaseId ? { testCaseId } : {}),
        });
        return {
            testId: testInfo.testId,
            attempt,
            executionId,
            ...(testCaseId ? { testCaseId } : {}),
        };
    }
}
exports.PlaywrightTestContextAdapter = PlaywrightTestContextAdapter;
