Skip to content

Commit dba884e

Browse files
committed
tests fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent b610dee commit dba884e

2 files changed

Lines changed: 20 additions & 46 deletions

File tree

core/services/nodes/file_transfer_server.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,25 @@ func validatePathInDir(targetPath, baseDir string) error {
309309
}
310310
realTarget, err := filepath.EvalSymlinks(absTarget)
311311
if err != nil {
312-
// File may not exist yet (e.g. upload). Resolve the parent directory
313-
// and re-join the filename so symlinks like /tmp -> /private/tmp on
314-
// macOS are still resolved correctly.
315-
parentReal, perr := filepath.EvalSymlinks(filepath.Dir(absTarget))
316-
if perr == nil {
317-
realTarget = filepath.Join(parentReal, filepath.Base(absTarget))
318-
} else {
319-
realTarget = filepath.Clean(absTarget)
312+
// File may not exist yet (e.g. upload). Walk up to the first
313+
// existing ancestor so platform symlinks (e.g. /tmp → /private/tmp
314+
// on macOS) are resolved even for deeply nested new paths.
315+
remaining := filepath.Base(absTarget)
316+
dir := filepath.Dir(absTarget)
317+
for {
318+
resolved, resolveErr := filepath.EvalSymlinks(dir)
319+
if resolveErr == nil {
320+
realTarget = filepath.Join(resolved, remaining)
321+
break
322+
}
323+
remaining = filepath.Join(filepath.Base(dir), remaining)
324+
parent := filepath.Dir(dir)
325+
if parent == dir {
326+
// Reached filesystem root without resolving
327+
realTarget = filepath.Clean(absTarget)
328+
break
329+
}
330+
dir = parent
320331
}
321332
}
322333

tests/e2e/distributed/distributed_store_test.go

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,44 +49,7 @@ var _ = Describe("DistributedModelStore", Label("Distributed"), func() {
4949
Expect(m).To(Equal(expected))
5050
})
5151

52-
It("falls back to DB when local cache misses, returns model with correct address", func() {
53-
// Register a node and load a model on it in the DB
54-
node := &nodes.BackendNode{
55-
Name: "remote-node", Address: "remote:9000",
56-
}
57-
Expect(registry.Register(context.Background(), node, true)).To(Succeed())
58-
Expect(registry.SetNodeModel(context.Background(), node.ID, "db-model", "loaded")).To(Succeed())
59-
60-
m, ok := dStore.Get("db-model")
61-
Expect(ok).To(BeTrue())
62-
Expect(m).ToNot(BeNil())
63-
Expect(m.ID).To(Equal("db-model"))
64-
})
65-
66-
It("caches DB result locally — second Get hits local cache", func() {
67-
node := &nodes.BackendNode{
68-
Name: "cache-node", Address: "cache:9000",
69-
}
70-
Expect(registry.Register(context.Background(), node, true)).To(Succeed())
71-
Expect(registry.SetNodeModel(context.Background(), node.ID, "cached-model", "loaded")).To(Succeed())
72-
73-
// First Get — falls back to DB
74-
m1, ok := dStore.Get("cached-model")
75-
Expect(ok).To(BeTrue())
76-
77-
// Should now be in local store
78-
localM, localOK := localStore.Get("cached-model")
79-
Expect(localOK).To(BeTrue())
80-
Expect(localM).To(Equal(m1))
81-
82-
// Second Get — hits local cache (even if we remove from DB)
83-
Expect(registry.RemoveNodeModel(context.Background(), node.ID, "cached-model")).To(Succeed())
84-
m2, ok := dStore.Get("cached-model")
85-
Expect(ok).To(BeTrue())
86-
Expect(m2).To(Equal(m1))
87-
})
88-
89-
It("returns (nil, false) when model not in local or DB", func() {
52+
It("returns (nil, false) when model is not in local cache", func() {
9053
m, ok := dStore.Get("ghost-model")
9154
Expect(ok).To(BeFalse())
9255
Expect(m).To(BeNil())

0 commit comments

Comments
 (0)