Skip to content

Commit

Permalink
fix(SDK): Artifact upload fails when same file referred multiple times (
Browse files Browse the repository at this point in the history
#715)

- [x] fix the bug where duplicate artifact references causing failure
during artifact resolution(typegate) during runtime.
- [x] add sync mode tests for Python and Deno runtime.
- [x] add other edge test cases to artifact upload.
    - [x] test for no artifact in typegraph
    - [x] test for duplicate artifact reference in the same typegraph

Issue:
[MET-501](https://linear.app/metatypedev/issue/MET-501/bug-artifact-upload-fails-when-same-file-refered-twice)

#### Migration notes

_No Migrations Needed_

...

<!-- 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 testing functionalities for Deno and Python runtimes,
supporting artifact deployment and policy enforcement.
- Added Python and Deno scripts for deploying Typegraphs and handling
runtime configurations.

- **Bug Fixes**
- Improved artifact handling and deployment logic in both Python and
Deno runtimes.

- **Tests**
- Added comprehensive test cases for Deno and Python runtimes, including
scenarios for duplicate artifacts, no artifacts, and runtime
synchronization.
- Enhanced testing with integration of various services like Redis and
S3.

- **Documentation**
- Updated test scripts to include detailed comments and summaries for
new functionalities and test scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Teo Stocco <[email protected]>
Co-authored-by: Teo Stocco <[email protected]>
Co-authored-by: Teo Stocco <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored May 15, 2024
1 parent 5db3ef8 commit bbdfd35
Show file tree
Hide file tree
Showing 12 changed files with 1,949 additions and 24 deletions.
68 changes: 68 additions & 0 deletions typegate/tests/runtimes/deno/deno_duplicate_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os
import sys

from typegraph.gen.exports.core import (
ArtifactResolutionConfig,
MigrationAction,
MigrationConfig,
)
from typegraph.graph.shared_types import BasicAuth
from typegraph.graph.tg_deploy import TypegraphDeployParams, tg_deploy
from typegraph.graph.typegraph import Graph
from typegraph.policy import Policy
from typegraph.runtimes.deno import DenoRuntime

from typegraph import t, typegraph


@typegraph()
def deno_duplicate_artifact(g: Graph):
deno = DenoRuntime()
public = Policy.public()

g.expose(
public,
doAddition=deno.import_(
t.struct({"a": t.float(), "b": t.float()}),
t.float(),
module="ts/dep/main.ts",
deps=["ts/dep/nested/dep.ts"],
name="doAddition",
),
doAdditionDuplicate=deno.import_(
t.struct({"a": t.float(), "b": t.float()}),
t.float(),
module="ts/dep/main.ts",
deps=["ts/dep/nested/dep.ts"],
name="doAddition",
),
)


cwd = sys.argv[1]
PORT = sys.argv[2]
gate = f"http://localhost:{PORT}"
auth = BasicAuth("admin", "password")

deno_tg = deno_duplicate_artifact()
deploy_result = tg_deploy(
deno_tg,
TypegraphDeployParams(
base_url=gate,
auth=auth,
typegraph_path=os.path.join(cwd, "deno_duplicate_artifact.py"),
artifacts_config=ArtifactResolutionConfig(
dir=cwd,
prefix=None,
disable_artifact_resolution=None,
codegen=None,
prisma_migration=MigrationConfig(
migration_dir="prisma-migrations",
global_action=MigrationAction(reset=False, create=True),
runtime_actions=None,
),
),
),
)

print(deploy_result.serialized)
33 changes: 33 additions & 0 deletions typegate/tests/runtimes/deno/deno_duplicate_artifact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Metatype OÜ, licensed under the Elastic License 2.0.
// SPDX-License-Identifier: Elastic-2.0

import { Policy, t, typegraph } from "@typegraph/sdk/index.js";
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js";

export const denoDuplicateArtifact = await typegraph({
name: "test_deno_dep",
}, (g) => {
const deno = new DenoRuntime();
const pub = Policy.public();

g.expose({
doAddition: deno.import(
t.struct({ a: t.float(), b: t.float() }),
t.float(),
{
module: "ts/dep/main.ts",
name: "doAddition",
deps: ["ts/dep/nested/dep.ts"],
},
).withPolicy(pub),
doAdditionDuplicate: deno.import(
t.struct({ a: t.float(), b: t.float() }),
t.float(),
{
module: "ts/dep/main.ts",
name: "doAddition",
deps: ["ts/dep/nested/dep.ts"],
},
).withPolicy(pub),
});
});
59 changes: 59 additions & 0 deletions typegate/tests/runtimes/deno/deno_no_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import sys

from typegraph.gen.exports.core import (
ArtifactResolutionConfig,
MigrationAction,
MigrationConfig,
)
from typegraph.graph.shared_types import BasicAuth
from typegraph.graph.tg_deploy import TypegraphDeployParams, tg_deploy
from typegraph.graph.typegraph import Graph
from typegraph.policy import Policy
from typegraph.runtimes.deno import DenoRuntime

from typegraph import t, typegraph


@typegraph()
def deno_no_artifact(g: Graph):
deno = DenoRuntime()
public = Policy.public()

g.expose(
public,
simple=deno.func(
t.struct({"a": t.float(), "b": t.float()}),
t.float(),
code="({ a, b }) => a + b",
),
)


cwd = sys.argv[1]
PORT = sys.argv[2]
gate = f"http://localhost:{PORT}"
auth = BasicAuth("admin", "password")

deno_tg = deno_no_artifact()
deploy_result = tg_deploy(
deno_tg,
TypegraphDeployParams(
base_url=gate,
auth=auth,
typegraph_path=os.path.join(cwd, "deno_no_artifact.py"),
artifacts_config=ArtifactResolutionConfig(
dir=cwd,
prefix=None,
disable_artifact_resolution=None,
codegen=None,
prisma_migration=MigrationConfig(
migration_dir="prisma-migrations",
global_action=MigrationAction(reset=False, create=True),
runtime_actions=None,
),
),
),
)

print(deploy_result.serialized)
Loading

0 comments on commit bbdfd35

Please sign in to comment.