import assert from "node:assert/strict";
import { test } from "node:test";
import { resolve } from "node:path";

import { buildAndValidatePortablePackage } from "../../scripts/lib/portable-package.mjs";

test("builds an isolated candidate portable package", async () => {
  const outputRoot = resolve(".build", "wp0-09-portable-test");
  const evidenceDirectory = process.env.DADA_EVIDENCE_DIR_PACKAGE
    ? resolve(process.env.DADA_EVIDENCE_DIR_PACKAGE)
    : undefined;
  const result = await buildAndValidatePortablePackage({ evidenceDirectory, outputRoot });

  assert.equal(result.status, "passed");
  assert.equal(result.packageManifest.fixed_port, 43121);
  assert.equal(result.packageManifest.release_status, "candidate_unvalidated");
  assert.equal(result.packageScan.disallowed_matches.length, 0);
  assert.equal(result.packageScan.reparse_points.length, 0);
  assert.equal(result.processTree.api.health.bind_scope, "loopback");
  assert.equal(result.processTree.api.health.port, 43121);
  assert.equal(result.processTree.api.release_gate.status_code, 426);
  assert.equal(result.processTree.native.status, "passed");
  assert.equal(result.processTree.supervisor.credential_store_access, false);
  assert.equal(result.processTree.supervisor.status, "passed");
});
