"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkLPXB254Rcjs = require('../chunk-LPXB254R.cjs');


var _chunkAGERRJ32cjs = require('../chunk-AGERRJ32.cjs');
require('../chunk-FUBHHHK5.cjs');


var _chunkQ5CW77ITcjs = require('../chunk-Q5CW77IT.cjs');
require('../chunk-NIYZDWMW.cjs');
require('../chunk-LNDVGTPQ.cjs');


var _chunkMMUXNMJFcjs = require('../chunk-MMUXNMJF.cjs');
require('../chunk-L47L3ZWJ.cjs');
require('../chunk-HDQ2JUQT.cjs');

// src/test/mod.ts
var _nodeserver = require('@hono/node-server');
var _nodews = require('@hono/node-ws');
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);

// src/test/log.ts
function logger() {
  return _chunkMMUXNMJFcjs.getLogger.call(void 0, "test");
}

// src/test/mod.ts
async function setupTest(c, registry) {
  var _a;
  registry.config.test = { ...registry.config.test, enabled: true };
  const driver = _chunkLPXB254Rcjs.createFileSystemOrMemoryDriver.call(void 0, 
    true,
    { path: `/tmp/rivetkit-test-${crypto.randomUUID()}` }
  );
  let upgradeWebSocket;
  registry.config.driver = driver;
  registry.config.inspector = {
    enabled: true,
    token: () => "token"
  };
  const parsedConfig = registry.parseConfig();
  const managerDriver = (_a = driver.manager) == null ? void 0 : _a.call(driver, parsedConfig);
  _invariant2.default.call(void 0, managerDriver, "missing manager driver");
  const getUpgradeWebSocket = () => upgradeWebSocket;
  managerDriver.setGetUpgradeWebSocket(getUpgradeWebSocket);
  const { router } = _chunkQ5CW77ITcjs.buildManagerRouter.call(void 0, 
    parsedConfig,
    managerDriver,
    getUpgradeWebSocket
  );
  const nodeWebSocket = _nodews.createNodeWebSocket.call(void 0, { app: router });
  upgradeWebSocket = nodeWebSocket.upgradeWebSocket;
  const server = _nodeserver.serve.call(void 0, {
    fetch: router.fetch,
    hostname: "127.0.0.1",
    port: 0
  });
  if (!server.listening) {
    await new Promise((resolve) => {
      server.once("listening", () => resolve());
    });
  }
  _invariant2.default.call(void 0, 
    nodeWebSocket.injectWebSocket !== void 0,
    "should have injectWebSocket"
  );
  nodeWebSocket.injectWebSocket(server);
  const address = server.address();
  _invariant2.default.call(void 0, address && typeof address !== "string", "missing server address");
  const port = address.port;
  const endpoint = `http://127.0.0.1:${port}`;
  logger().info({ msg: "test server listening", port });
  c.onTestFinished(async () => {
    await new Promise((resolve) => server.close(() => resolve(void 0)));
  });
  const client = _chunkAGERRJ32cjs.createClient.call(void 0, {
    endpoint,
    namespace: "default",
    runnerName: "default",
    disableMetadataLookup: true
  });
  c.onTestFinished(async () => await client.dispose());
  return { client };
}


exports.setupTest = setupTest;
//# sourceMappingURL=mod.cjs.map