Skip to content

Commit

Permalink
feat(meta-test): update t.engine() impl (#716)
Browse files Browse the repository at this point in the history
Update the implementation of `t.engine()`

<!-- 1. Explain below WHAT the change is -->

The change comes with removing the different spin-offs of `t.engine`
which arose from the previous impl of t.engine incompatibility with
artifact upload protocol. The change will make `t.engine` deploy the
artifacts in Artifact Resolution mode by running a shell command to
deploy the typegraph.

<!-- 2. Explain below WHY the change cannot be made simpler -->

...

<!-- 3. Explain below WHY the was made or link an issue number -->


[MET-500](https://linear.app/metatypedev/issue/MET-500/test-update-the-implementation-of-tengine)

<!-- 4. Explain HOW users should update their code or remove that
section -->

- [x] remove different versions of `t.engine`
- [x] add tg_deploy caller script which imports typegraphs dynamically
and deploys them.
- [x] make changes to make `t.engine` run in artifact resolution mode 
- [x] update existing tests to adhere to the current change
- [x] pass unique different `tempDir`s to all the typegate instances
created during test.
- [x] add support for authoring multiple typegraphs in a single file in
`meta-test` and add multi typegraph tests.

#### Migration notes

python SDK test typegraphs' function names should be the same with the
filename of the typegraph file, for dynamic import compatibility
reasons.

<!-- 5. Readiness checklist
- [ ] The change come with new or modified tests
- [ ] Hard-to-understand functions have explanatory comments
- [ ] End-user documentation is updated to reflect the change
-->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new function `wasm_duplicate` to handle WebAssembly
runtimes with specific policies.

- **Refactor**
- Renamed and refactored functions and test setups to align with updated
test frameworks and improve code clarity.

- **Bug Fixes**
- Added error handling in the `getLocalPath` function to log warnings if
linking errors occur.

- **Tests**
- Updated test scripts to reflect changes in function calls, imports,
and engine instantiation for better test accuracy and reliability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
destifo committed May 25, 2024
1 parent cca3962 commit f951bd1
Show file tree
Hide file tree
Showing 96 changed files with 1,792 additions and 2,315 deletions.
22 changes: 1 addition & 21 deletions .ghjk/lock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "0",
"platform": "x86_64-linux",
"platform": "aarch64-darwin",
"moduleEntries": {
"ports": {
"version": "0",
Expand Down Expand Up @@ -598,7 +598,6 @@
"69cc04434a8b51a9d34210383f1a931646772e3b",
"8e5e02544073c4733d8f2156c404a0dd524cdaaf",
"54eba38cb79f88fca14cd3185e5bec0c3dd02682",
"e05f859f4a734a85fd3439f9b0fc0de1e733bdac",
"38285a3b335e394ccce5ac5d59e15f660bfa4cc9",
"7bbf00da8e265c56c2bff5bb7d89ba806e2590d2",
"14fd3752a984c5d82e1451f7388c73a21fcce705",
Expand Down Expand Up @@ -1118,25 +1117,6 @@
"crateName": "cross",
"locked": true
},
"e05f859f4a734a85fd3439f9b0fc0de1e733bdac": {
"version": "v2.4.0",
"port": {
"ty": "denoWorker@v1",
"name": "mold_ghrel",
"platforms": [
"aarch64-linux",
"x86_64-linux"
],
"version": "0.1.0",
"deps": [
{
"name": "tar_aa"
}
],
"moduleSpecifier": "https://raw.githubusercontent.com/metatypedev/ghjk/2725af8/ports/mold.ts"
},
"replaceLd": false
},
"38285a3b335e394ccce5ac5d59e15f660bfa4cc9": {
"version": "3.8.18",
"port": {
Expand Down
51 changes: 24 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/xtask/src/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Test {
allow_run: Some(
[
"cargo", "hostname", "meta", "git", "python3", "rm", "mkdir", "bash", "npm",
"pnpm", "setsid", "temporal",
"pnpm", "setsid", "temporal", "deno",
]
.into_iter()
.map(str::to_owned)
Expand Down
4 changes: 3 additions & 1 deletion typegate/src/typegate/artifacts/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export async function getLocalPath(
await Deno.mkdir(dirname(localPath), { recursive: true });
// the old artifacts are always removed on typegraph update.
await Deno.remove(localPath, { recursive: true }).catch(() => {});
await Deno.link(cachedPath, localPath);
await Deno.link(cachedPath, localPath).catch((msg) => {
logger.warn(msg);
});

return localPath;
}
Expand Down
34 changes: 22 additions & 12 deletions typegate/tests/artifacts/artifacts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Elastic-2.0

import { Meta } from "test-utils/mod.ts";
import { MetaTest } from "test-utils/test.ts";
import { testDir } from "test-utils/dir.ts";
import { join } from "std/path/join.ts";
import { exists } from "std/fs/exists.ts";
import { assert, assertFalse } from "std/assert/mod.ts";
Expand All @@ -14,6 +12,7 @@ import {
REDIS_REF_COUNTER,
resolveS3Key,
} from "@typegate/typegate/artifacts/shared.ts";
import { MetaTest } from "../utils/test.ts";

const syncConfig = {
redis: {
Expand Down Expand Up @@ -84,15 +83,19 @@ for (const { nameSuffix, ...options } of variants) {

await t.should("have uploaded artifacts on deploy", async () => {
for (const [_, meta] of Object.entries(artifacts)) {
assert(await hasArtifact(t, meta.hash, "syncConfig" in options));
const typedMeta = meta as { hash: string };
assert(await hasArtifact(t, typedMeta.hash, "syncConfig" in options));
}
});

await t.undeploy(e.name);

await t.should("have removed artifacts on undeploy", async () => {
for (const [_, meta] of Object.entries(artifacts)) {
assertFalse(await hasArtifact(t, meta.hash, "syncConfig" in options));
const typedMeta = meta as { hash: string };
assertFalse(
await hasArtifact(t, typedMeta.hash, "syncConfig" in options),
);
}
});
});
Expand All @@ -108,23 +111,26 @@ for (const { nameSuffix, ...options } of variants) {
name: "Upload protocol: tg_deploy (Python SDK)" + nameSuffix,
...options,
}, async (t) => {
const e = await t.engineFromTgDeployPython(
"runtimes/deno/deploy_deno.py",
join(testDir, "runtimes/deno"),
const e = await t.engine(
"runtimes/deno/deno.py",
);
const artifacts = e.tg.tg.meta.artifacts;

await t.should("have uploaded artifacts on deploy", async () => {
for (const [_, meta] of Object.entries(artifacts)) {
assert(await hasArtifact(t, meta.hash, "syncConfig" in options));
const typedMeta = meta as { hash: string };
assert(await hasArtifact(t, typedMeta.hash, "syncConfig" in options));
}
});

await t.undeploy(e.name);

await t.should("have removed artifacts on undeploy", async () => {
for (const [_, meta] of Object.entries(artifacts)) {
assertFalse(await hasArtifact(t, meta.hash, "syncConfig" in options));
const typedMeta = meta as { hash: string };
assertFalse(
await hasArtifact(t, typedMeta.hash, "syncConfig" in options),
);
}
});
});
Expand All @@ -144,10 +150,13 @@ for (const { nameSuffix, ...options } of variants) {

await t.should("have removed shared artifacts", async () => {
for (const [art, meta] of Object.entries(artifacts)) {
const typedMeta = meta as { hash: string };
if (sharedArtifacts.includes(art)) {
assert(await hasArtifact(t, meta.hash, "syncConfig" in options));
assert(await hasArtifact(t, typedMeta.hash, "syncConfig" in options));
} else {
assertFalse(await hasArtifact(t, meta.hash, "syncConfig" in options));
assertFalse(
await hasArtifact(t, typedMeta.hash, "syncConfig" in options),
);
}
}
});
Expand All @@ -156,8 +165,9 @@ for (const { nameSuffix, ...options } of variants) {

await t.should("have removed all artifacts", async () => {
for (const [_, meta] of Object.entries(artifacts)) {
const typedMeta = meta as { hash: string };
assertFalse(
await hasArtifact(t, meta.hash, "syncConfig" in options),
await hasArtifact(t, typedMeta.hash, "syncConfig" in options),
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion typegate/tests/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@typegraph(
name="test_auth",
)
def test_auth(g: Graph):
def auth(g: Graph):
deno = DenoRuntime()
python = PythonRuntime()
remote = HttpRuntime("https://api.github.com")
Expand Down
Loading

0 comments on commit f951bd1

Please sign in to comment.