From 5ba4402dc2090900b1f2a2b77dc67e40d332ccf7 Mon Sep 17 00:00:00 2001
From: Tsiry Sandratraina <tsiry.sndr@fluentci.io>
Date: Mon, 18 Mar 2024 05:42:22 +0000
Subject: [PATCH] ci: add e2e tests for typescript sdk

ci: add e2e tests for typescript sdk

remove unused imports

fix ci

fix ci
---
 .fluentci/src/dagger/index.ts | 12 ++++++---
 .fluentci/src/dagger/jobs.ts  | 51 +++++++++++++++++++++++++++++++++++
 .github/workflows/ci.yml      |  8 +++++-
 crates/ext/src/flox.rs        |  2 +-
 4 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/.fluentci/src/dagger/index.ts b/.fluentci/src/dagger/index.ts
index adb2f6b..59c9c3b 100644
--- a/.fluentci/src/dagger/index.ts
+++ b/.fluentci/src/dagger/index.ts
@@ -1,3 +1,9 @@
-import { clippy, build, test, llvmCov, e2e, jobDescriptions } from "./jobs.ts";
-
-export { clippy, build, test, llvmCov, e2e, jobDescriptions };
+export {
+  clippy,
+  build,
+  test,
+  llvmCov,
+  e2e,
+  typescriptE2e,
+  jobDescriptions,
+} from "./jobs.ts";
diff --git a/.fluentci/src/dagger/jobs.ts b/.fluentci/src/dagger/jobs.ts
index de1e202..4fece55 100644
--- a/.fluentci/src/dagger/jobs.ts
+++ b/.fluentci/src/dagger/jobs.ts
@@ -11,6 +11,7 @@ export enum Job {
   build = "build",
   llvmCov = "llvm_cov",
   e2e = "e2e",
+  typescriptE2e = "typescript_e2e",
 }
 
 export const exclude = ["target", ".git", ".devbox", ".fluentci"];
@@ -310,6 +311,54 @@ export async function e2e(
   return stdout;
 }
 
+/**
+ *  Run e2e tests for typescript sdk
+ *
+ * @function
+ * @description Run e2e tests for typescript sdk
+ * @param {string | Directory | undefined} src
+ * @param {string[]} options
+ * @returns {string}
+ */
+export async function typescriptE2e(
+  src: string | Directory | undefined = ".",
+  options: string[] = []
+): Promise<string> {
+  const context = await getDirectory(env.get("WORK_DIR") || src);
+  const engine = dag
+    .container()
+    .from("debian:bookworm")
+    .withExec(["apt-get", "update"])
+    .withExec(["apt-get", "install", "-y", "curl", "ca-certificates", "git"])
+    .withDirectory("/app", context, { exclude })
+    .withWorkdir("/app")
+    .withFile(
+      "/fluentci-engine",
+      dag.host().file("./target/release/fluentci-engine")
+    )
+    .withEnvVariable("FLUENTCI_ENGINE_HOST", "0.0.0.0")
+    .withExec(["/fluentci-engine"])
+    .withExposedPort(6880)
+    .asService();
+
+  const ctr = await dag
+    .pipeline(Job.typescriptE2e)
+    .container()
+    .from("pkgxdev/pkgx:latest")
+    .withExec(["pkgx", "install", "deno"])
+    .withExec(["deno", "--version"])
+    .withDirectory("/app", context, { exclude })
+    .withWorkdir("/app/demo")
+    .withServiceBinding("fluentci-engine", engine)
+    .sync();
+
+  const stdout = await ctr.withExec(["deno", "run", "-A", "main.ts"]).stdout();
+
+  console.log(stdout);
+
+  return stdout;
+}
+
 export type JobExec =
   | ((src?: string | Directory | undefined) => Promise<Directory | string>)
   | ((src?: string | Directory | undefined) => Promise<File | string>)
@@ -319,6 +368,7 @@ export const runnableJobs: Record<Job, JobExec> = {
   [Job.clippy]: clippy,
   [Job.test]: test,
   [Job.e2e]: e2e,
+  [Job.typescriptE2e]: typescriptE2e,
   [Job.build]: build,
   [Job.llvmCov]: llvmCov,
 };
@@ -327,6 +377,7 @@ export const jobDescriptions: Record<Job, string> = {
   [Job.clippy]: "Run clippy",
   [Job.test]: "Run tests",
   [Job.e2e]: "Run e2e tests",
+  [Job.typescriptE2e]: "Run e2e tests for typescript sdk",
   [Job.build]: "Build the project",
   [Job.llvmCov]: "Generate llvm coverage report",
 };
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8e612b5..148992a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -10,7 +10,7 @@ jobs:
       - uses: actions/checkout@v2
       - name: Setup Fluent CI
         uses: fluentci-io/setup-fluentci@v4
-      - name: Run Dagger Pipelines
+      - name: Run Build and e2e tests
         run: |
           fluentci run rust_pipeline build
           ls -ltr target
@@ -21,3 +21,9 @@ jobs:
           FLUENTCI_ENGINE_HOST: 0.0.0.0
           WORK_DIR: ./fixtures
           DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}
+      - name: Run e2e tests (typescript sdk)
+        run: fluentci run . typescript_e2e
+        env:
+          FLUENTCI_ENGINE_HOST: 0.0.0.0
+          WORK_DIR: ./sdk/typescript
+          DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}
diff --git a/crates/ext/src/flox.rs b/crates/ext/src/flox.rs
index c48716b..702f8fd 100644
--- a/crates/ext/src/flox.rs
+++ b/crates/ext/src/flox.rs
@@ -1,6 +1,6 @@
 use std::{
     process::{Command, ExitStatus, Stdio},
-    sync::mpsc::{self, Receiver, Sender},
+    sync::mpsc::Sender,
 };
 
 use crate::{exec, nix::Nix, Extension};