Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions packages/cli/tests/checkin/destructive_cache_cyclic_dependencies.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
use ../../test.nu *

let server = spawn

# Check for cyclic dependencies.
let path = artifact {
foo: {
tangram.ts: 'import * as bar from "../bar";'
}
bar: {
tangram.ts: 'import * as foo from "../foo";'
}
}
let id = tg checkin --destructive $path --ignore=false
tg index

let object = tg object get --blobs --depth=inf --pretty $id
snapshot $object '
tg.directory({
"bar": {
"graph": tg.graph({
"nodes": [
{
"kind": "file",
"contents": tg.blob("import * as bar from \"../bar\";"),
"dependencies": {
"../bar": {
"item": {
"index": 2,
"kind": "directory",
},
"options": {
"path": "../bar",
},
},
},
"module": "ts",
},
{
"kind": "directory",
"entries": {
"tangram.ts": {
"index": 0,
"kind": "file",
},
},
},
{
"kind": "directory",
"entries": {
"tangram.ts": {
"index": 3,
"kind": "file",
},
},
},
{
"kind": "file",
"contents": tg.blob("import * as foo from \"../foo\";"),
"dependencies": {
"../foo": {
"item": {
"index": 1,
"kind": "directory",
},
"options": {
"path": "../foo",
},
},
},
"module": "ts",
},
],
}),
"index": 2,
"kind": "directory",
},
"foo": {
"graph": tg.graph({
"nodes": [
{
"kind": "file",
"contents": tg.blob("import * as bar from \"../bar\";"),
"dependencies": {
"../bar": {
"item": {
"index": 2,
"kind": "directory",
},
"options": {
"path": "../bar",
},
},
},
"module": "ts",
},
{
"kind": "directory",
"entries": {
"tangram.ts": {
"index": 0,
"kind": "file",
},
},
},
{
"kind": "directory",
"entries": {
"tangram.ts": {
"index": 3,
"kind": "file",
},
},
},
{
"kind": "file",
"contents": tg.blob("import * as foo from \"../foo\";"),
"dependencies": {
"../foo": {
"item": {
"index": 1,
"kind": "directory",
},
"options": {
"path": "../foo",
},
},
},
"module": "ts",
},
],
}),
"index": 1,
"kind": "directory",
},
})
'
42 changes: 42 additions & 0 deletions packages/cli/tests/checkin/destructive_cache_id_dependency.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use ../../test.nu *
let remote = spawn --name 'remote'
let server = spawn --name 'local' --config {
remotes: [{
name: 'default',
url: $remote.url
}]
}

let dep_path = artifact {
tangram.ts: 'export default () => "dep";'
}
let dep_id = tg checkin --destructive --ignore=false $dep_path
tg index

let path = artifact {
tangram.ts: $'
import dep from "($dep_id)";
'
}
let id = tg checkin --destructive $path --ignore=false
tg index

let object = tg object get --blobs --depth=inf --pretty $id
snapshot $object '
tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("import dep from \"dir_01eg1hz5n9tvjmzbsvxgwegxa5jnx10pgpx47k99b9z200v7kqdm7g\";"),
"dependencies": {
"dir_01eg1hz5n9tvjmzbsvxgwegxa5jnx10pgpx47k99b9z200v7kqdm7g": {
"item": tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("export default () => \"dep\";"),
"module": "ts",
}),
}),
},
},
"module": "ts",
}),
})
'
45 changes: 45 additions & 0 deletions packages/cli/tests/checkin/destructive_cache_path_dependency.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use ../../test.nu *

let server = spawn

let path = artifact {
foo: {
tangram.ts: 'import * as bar from "../bar";'
}
bar: {
tangram.ts: 'export default () => "bar";'
}
}
let id = tg checkin --destructive $path --ignore=false
tg index

let object = tg object get --blobs --depth=inf --pretty $id
snapshot $object '
tg.directory({
"bar": tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("export default () => \"bar\";"),
"module": "ts",
}),
}),
"foo": tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("import * as bar from \"../bar\";"),
"dependencies": {
"../bar": {
"item": tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("export default () => \"bar\";"),
"module": "ts",
}),
}),
"options": {
"path": "../bar",
},
},
},
"module": "ts",
}),
}),
})
'
44 changes: 44 additions & 0 deletions packages/cli/tests/checkin/destructive_cache_tag_dependency.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use ../../test.nu *

let server = spawn

# Check that using a tag dependency in the cache works.
let a_path = artifact {
tangram.ts: '
export default () => "a";
'
}
tg tag a $a_path
tg index

let path = artifact {
tangram.ts: '
import a from "a";
'
}
let id = tg checkin --destructive $path --ignore=false
tg index

let object = tg object get --blobs --depth=inf --pretty $id
snapshot $object '
tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("import a from \"a\";"),
"dependencies": {
"a": {
"item": tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("export default () => \"a\";"),
"module": "ts",
}),
}),
"options": {
"id": "dir_01397yyk1pe2sv1ddct0f0aq0qtxjbjtw55t9d7vke752ezc8at4p0",
"tag": "a",
},
},
},
"module": "ts",
}),
})
'
15 changes: 15 additions & 0 deletions packages/cli/tests/checkin/destructive_external_path_dependency.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use ../../test.nu *

let server = spawn

# Check that we cannot destructively checkin artifacts with external paths.
let path = artifact {
foo: {
tangram.ts: 'import * as bar from "../bar";'
}
bar: {
tangram.ts: ''
}
}
let output = tg checkin --destructive ($path | path join 'foo') --ignore=false | complete
failure $output "destructive checkin with external path dependencies should fail"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use ../../test.nu *
let remote = spawn --name 'remote'
let server = spawn --name 'local' --config {
remotes: [{
name: 'default',
url: $remote.url
}]
}

# Check that destructive checkin fails when a tag dependency is only on the remote and not in the local cache.
let remote_dep_path = artifact {
tangram.ts: '
export default () => "remote_only";
'
}
tg -u $remote.url tag remote_dep $remote_dep_path

let path = artifact {
tangram.ts: '
import remote_dep from "remote_dep";
'
}
let id = tg checkin --destructive $path --ignore=false
let object = tg get $id --depth=inf --blobs --pretty
snapshot $object '
tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("import remote_dep from \"remote_dep\";"),
"dependencies": {
"remote_dep": {
"item": tg.directory({
"tangram.ts": tg.file({
"contents": tg.blob("export default () => \"remote_only\";"),
"module": "ts",
}),
}),
"options": {
"id": "dir_01stfjn9km4b3vq5w8bgqc0xdgkwwn4307p5kysj41z1gsvacytp1g",
"tag": "remote_dep",
},
},
},
"module": "ts",
}),
})
'
18 changes: 15 additions & 3 deletions packages/server/src/checkin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type IndexCacheEntryArgs = Vec<tangram_index::PutCacheEntryArg>;

type StoreArgs = IndexMap<tg::object::Id, crate::store::PutObjectArg, tg::id::BuildHasher>;

type GraphData = IndexMap<tg::graph::Id, tg::graph::Data, tg::id::BuildHasher>;

impl Server {
#[tracing::instrument(fields(path = ?arg.path), level = "trace", name = "checkin", skip_all)]
pub(crate) async fn checkin_with_context(
Expand Down Expand Up @@ -365,6 +367,7 @@ impl Server {
let mut store_args = IndexMap::default();
let mut index_object_args = IndexMap::default();
let mut index_cache_entry_args = Vec::new();
let mut graph_data = IndexMap::default();

// Create blobs.
self.checkin_create_blobs(
Expand All @@ -389,6 +392,7 @@ impl Server {
&mut store_args,
&mut index_object_args,
&mut index_cache_entry_args,
&mut graph_data,
root,
touched_at,
)?;
Expand All @@ -399,9 +403,17 @@ impl Server {
task.await
.map_err(|source| tg::error!(!source, "failed to run the fixup task"))?;
}
self.checkin_cache(&arg, &graph, next, root, progress)
.await
.map_err(|source| tg::error!(!source, "failed to cache"))?;
self.checkin_cache(
&arg,
&graph,
next,
root,
&index_cache_entry_args,
&mut graph_data,
progress,
)
.await
.map_err(|source| tg::error!(!source, "failed to cache"))?;
}

// Store.
Expand Down
Loading