@intuned/runtime-dev 0.1.0-test.27 → 0.1.0-test.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,59 +40,61 @@ export async function runEndpointAsync<_Parameters extends any[], _Result>(
40
40
  } catch (e: any) {
41
41
  console.error(`Error running ${requestId} in async mode:`, e);
42
42
  ({ status, body } = getErrorResponse(e));
43
- } finally {
44
- AsyncRunEndpointController.removeRequest(taskToken);
45
- }
46
43
 
47
- // report result
48
- console.log("Reporting result for", requestId);
49
- try {
50
- // `retry` will keep retrying any errors unless they are thrown through calling `bail`
51
- await retry(
52
- async (bail: (e: Error) => void) => {
53
- const response = await callBackendFunctionWithToken(
54
- "run/reportResult",
55
- {
56
- method: "POST",
57
- headers: {
58
- "Content-Type": "application/json",
59
- "fly-instance-id": process.env.FLY_ALLOC_ID ?? "",
60
- },
61
- body: JSON.stringify({
62
- status,
63
- body,
64
- startTime,
65
- taskToken,
66
- }),
44
+ // report result
45
+ console.log("Reporting result for", requestId);
46
+ try {
47
+ // `retry` will keep retrying any errors unless they are thrown through calling `bail`
48
+ await retry(
49
+ async (bail: (e: Error) => void) => {
50
+ const response = await callBackendFunctionWithToken(
51
+ "run/reportResult",
52
+ {
53
+ method: "POST",
54
+ headers: {
55
+ "Content-Type": "application/json",
56
+ "fly-instance-id": process.env.FLY_ALLOC_ID ?? "",
57
+ },
58
+ body: JSON.stringify({
59
+ status,
60
+ body,
61
+ startTime,
62
+ taskToken,
63
+ }),
64
+ }
65
+ ).catch((e) => {
66
+ const message = `Reporting result failed for ${requestId}, error: ${e.message}`;
67
+ console.error(message);
68
+ throw e;
69
+ });
70
+ if (!response.ok) {
71
+ // Do not retry unauthenticated, forbidden, not found or too large responses
72
+ if ([401, 403, 404, 413].includes(response.status)) {
73
+ const message = `Reporting result failed for ${requestId} (non-retryable), status ${response.status}`;
74
+ console.error(message);
75
+ bail(new Error(message));
76
+ }
77
+ // retry other errors (such as 502)
78
+ const message = `Reporting result failed for ${requestId}, status ${response.status}`;
79
+ console.error(message);
80
+ throw new Error(message);
67
81
  }
68
- );
69
- if (!response.ok) {
70
- // Do not retry unauthenticated, forbidden, not found or too large responses
71
- if ([401, 403, 404, 413].includes(response.status)) {
72
- bail(
73
- new Error(
74
- `Reporting result failed for ${requestId} (non-retryable), status ${response.status}`
75
- )
76
- );
77
- }
78
- // retry other errors (such as 502)
79
- throw new Error(
80
- `Reporting result failed for ${requestId}, status ${response.status}`
81
- );
82
- }
83
82
 
84
- return response;
85
- },
86
- {
87
- retries: 5,
88
- factor: 2,
89
- maxTimeout: 1000 * 60, // 1 minute
90
- minTimeout: 1000 * 5, // 5 seconds
91
- }
92
- );
93
- console.log("Reported result for", requestId);
94
- } catch (e: any) {
95
- console.log(e?.message ?? `Reporting result failed for ${requestId}`);
83
+ return response;
84
+ },
85
+ {
86
+ retries: 5,
87
+ factor: 2,
88
+ maxTimeout: 1000 * 60, // 1 minute
89
+ minTimeout: 1000 * 5, // 5 seconds
90
+ }
91
+ );
92
+ console.log("Reported result for", requestId);
93
+ } catch (e: any) {
94
+ // ignore
95
+ }
96
+ } finally {
97
+ AsyncRunEndpointController.removeRequest(taskToken);
96
98
  }
97
99
 
98
100
  await ShutdownController.instance.checkForShutdown();
@@ -1,11 +1,7 @@
1
1
  import { authSessionsContextsStore } from "./store";
2
2
  import { getTraceFilePath, isHeadless, importModule } from "../../utils";
3
3
  import * as fs from "fs-extra";
4
- import {
5
- runApiGenerator,
6
- type RunApiResult,
7
- type RunApiResultWithSessionOk,
8
- } from "@intuned/runtime/dist/common/runApi";
4
+ import { runApiGenerator } from "@intuned/runtime/dist/common/runApi";
9
5
  import type { RequestMoreInfoDetails } from "@intuned/runtime/dist/runtime";
10
6
 
11
7
  export async function createAuthSession({
@@ -33,7 +33,7 @@ export async function resumeAuthSessionOperation({
33
33
 
34
34
  const result = await operation.generator.next(input);
35
35
 
36
- if (result.done) {
36
+ if (result.done === true) {
37
37
  authSessionsContextsStore.delete(operationId);
38
38
  if (result.value.isErr()) {
39
39
  return result.value.error.apiResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "0.1.0-test.27",
3
+ "version": "0.1.0-test.29",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -0,0 +1,43 @@
1
+ import { defineConfig, devices } from "@intuned/playwright-test";
2
+ /**
3
+ * Read environment variables from file.
4
+ * https://github.com/motdotla/dotenv
5
+ */
6
+ // require('dotenv').config();
7
+ /**
8
+ * See https://playwright.dev/docs/test-configuration.
9
+ */
10
+ export default defineConfig({
11
+ testDir: "./e2e-tests",
12
+ /* Run tests in files in parallel */
13
+ fullyParallel: true,
14
+ /* Fail the build on CI if you accidentally left test.only in the source code. */
15
+ forbidOnly: !!process.env.CI,
16
+ /* Retry on CI only */
17
+ retries: process.env.CI ? 2 : 0,
18
+ /* Opt out of parallel tests on CI. */
19
+ workers: process.env.CI ? 1 : undefined,
20
+ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
21
+ reporter: "html",
22
+ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
23
+ use: {
24
+ /* Base URL to use in actions like `await page.goto('/')`. */
25
+ // baseURL: 'http://127.0.0.1:3000',
26
+ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
27
+ trace: "on-first-retry",
28
+ // headless: false,
29
+ },
30
+ /* Configure projects for major browsers */
31
+ projects: [
32
+ {
33
+ name: "chromium",
34
+ use: { ...devices["Desktop Chrome"] },
35
+ },
36
+ ],
37
+ /* Run your local dev server before starting the tests */
38
+ // webServer: {
39
+ // command: 'npm run start',
40
+ // url: 'http://127.0.0.1:3000',
41
+ // reuseExistingServer: !process.env.CI,
42
+ // },
43
+ });
package/vite.config.js ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "vite";
2
+ import macros from "vite-plugin-babel-macros";
3
+ require('dotenv').config();
4
+ export default defineConfig({
5
+ test: {
6
+ reporters: ['verbose', "html"],
7
+ outputFile: { html: './reports/html/index.html' },
8
+ testTimeout: 30000,
9
+ env: {
10
+ RUN_ENVIRONMENT: "AUTHORING",
11
+ }
12
+ },
13
+ plugins: [
14
+ macros(),
15
+ ],
16
+ });