mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
create version graph to handle migrations (#2708)
* create version graph to handle migrations * Fix some version alpha test * connect dataVersion api * rename init fns * improve types and add tests * set data version after backup restore * chore: Add some types tests for version info * wip: More changes to versionInfo tests * wip: fix my stupid * update mocks * update runtime * chore: Fix the loop --------- Co-authored-by: Jade <2364004+Blu-J@users.noreply.github.com> Co-authored-by: J H <dragondef@gmail.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import { Variants } from "../config/builder/variants"
|
||||
import { ValueSpec } from "../config/configTypes"
|
||||
import { setupManifest } from "../manifest/setupManifest"
|
||||
import { StartSdk } from "../StartSdk"
|
||||
import { VersionGraph } from "../versionInfo/setupVersionGraph"
|
||||
import { VersionInfo } from "../versionInfo/VersionInfo"
|
||||
|
||||
describe("builder tests", () => {
|
||||
test("text", async () => {
|
||||
@@ -366,42 +368,48 @@ describe("values", () => {
|
||||
test("datetime", async () => {
|
||||
const sdk = StartSdk.of()
|
||||
.withManifest(
|
||||
setupManifest({
|
||||
id: "testOutput",
|
||||
title: "",
|
||||
version: "1.0.0:0",
|
||||
releaseNotes: "",
|
||||
license: "",
|
||||
replaces: [],
|
||||
wrapperRepo: "",
|
||||
upstreamRepo: "",
|
||||
supportSite: "",
|
||||
marketingSite: "",
|
||||
donationUrl: null,
|
||||
description: {
|
||||
short: "",
|
||||
long: "",
|
||||
},
|
||||
containers: {},
|
||||
images: {},
|
||||
volumes: [],
|
||||
assets: [],
|
||||
alerts: {
|
||||
install: null,
|
||||
update: null,
|
||||
uninstall: null,
|
||||
restore: null,
|
||||
start: null,
|
||||
stop: null,
|
||||
},
|
||||
dependencies: {
|
||||
"remote-test": {
|
||||
description: "",
|
||||
optional: true,
|
||||
s9pk: "https://example.com/remote-test.s9pk",
|
||||
setupManifest(
|
||||
{
|
||||
id: "testOutput",
|
||||
title: "",
|
||||
license: "",
|
||||
wrapperRepo: "",
|
||||
upstreamRepo: "",
|
||||
supportSite: "",
|
||||
marketingSite: "",
|
||||
donationUrl: null,
|
||||
description: {
|
||||
short: "",
|
||||
long: "",
|
||||
},
|
||||
containers: {},
|
||||
images: {},
|
||||
volumes: [],
|
||||
assets: [],
|
||||
alerts: {
|
||||
install: null,
|
||||
update: null,
|
||||
uninstall: null,
|
||||
restore: null,
|
||||
start: null,
|
||||
stop: null,
|
||||
},
|
||||
dependencies: {
|
||||
"remote-test": {
|
||||
description: "",
|
||||
optional: true,
|
||||
s9pk: "https://example.com/remote-test.s9pk",
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
VersionGraph.of(
|
||||
VersionInfo.of({
|
||||
version: "1.0.0:0",
|
||||
releaseNotes: "",
|
||||
migrations: {},
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
.withStore<{ test: "a" }>()
|
||||
.build(true)
|
||||
|
||||
148
sdk/lib/test/graph.test.ts
Normal file
148
sdk/lib/test/graph.test.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
import { Graph } from "../util/graph"
|
||||
|
||||
describe("graph", () => {
|
||||
{
|
||||
{
|
||||
test("findVertex", () => {
|
||||
const graph = new Graph<string, string>()
|
||||
const foo = graph.addVertex("foo", [], [])
|
||||
const bar = graph.addVertex(
|
||||
"bar",
|
||||
[{ from: foo, metadata: "foo-bar" }],
|
||||
[],
|
||||
)
|
||||
const baz = graph.addVertex(
|
||||
"baz",
|
||||
[{ from: bar, metadata: "bar-baz" }],
|
||||
[],
|
||||
)
|
||||
const qux = graph.addVertex(
|
||||
"qux",
|
||||
[{ from: baz, metadata: "baz-qux" }],
|
||||
[],
|
||||
)
|
||||
const match = Array.from(graph.findVertex((v) => v.metadata === "qux"))
|
||||
expect(match).toHaveLength(1)
|
||||
expect(match[0]).toBe(qux)
|
||||
})
|
||||
test("shortestPathA", () => {
|
||||
const graph = new Graph<string, string>()
|
||||
const foo = graph.addVertex("foo", [], [])
|
||||
const bar = graph.addVertex(
|
||||
"bar",
|
||||
[{ from: foo, metadata: "foo-bar" }],
|
||||
[],
|
||||
)
|
||||
const baz = graph.addVertex(
|
||||
"baz",
|
||||
[{ from: bar, metadata: "bar-baz" }],
|
||||
[],
|
||||
)
|
||||
const qux = graph.addVertex(
|
||||
"qux",
|
||||
[{ from: baz, metadata: "baz-qux" }],
|
||||
[],
|
||||
)
|
||||
graph.addEdge("foo-qux", foo, qux)
|
||||
expect(graph.shortestPath(foo, qux) || []).toHaveLength(1)
|
||||
})
|
||||
test("shortestPathB", () => {
|
||||
const graph = new Graph<string, string>()
|
||||
const foo = graph.addVertex("foo", [], [])
|
||||
const bar = graph.addVertex(
|
||||
"bar",
|
||||
[{ from: foo, metadata: "foo-bar" }],
|
||||
[],
|
||||
)
|
||||
const baz = graph.addVertex(
|
||||
"baz",
|
||||
[{ from: bar, metadata: "bar-baz" }],
|
||||
[],
|
||||
)
|
||||
const qux = graph.addVertex(
|
||||
"qux",
|
||||
[{ from: baz, metadata: "baz-qux" }],
|
||||
[],
|
||||
)
|
||||
graph.addEdge("bar-qux", bar, qux)
|
||||
expect(graph.shortestPath(foo, qux) || []).toHaveLength(2)
|
||||
})
|
||||
test("shortestPathC", () => {
|
||||
const graph = new Graph<string, string>()
|
||||
const foo = graph.addVertex("foo", [], [])
|
||||
const bar = graph.addVertex(
|
||||
"bar",
|
||||
[{ from: foo, metadata: "foo-bar" }],
|
||||
[],
|
||||
)
|
||||
const baz = graph.addVertex(
|
||||
"baz",
|
||||
[{ from: bar, metadata: "bar-baz" }],
|
||||
[],
|
||||
)
|
||||
const qux = graph.addVertex(
|
||||
"qux",
|
||||
[{ from: baz, metadata: "baz-qux" }],
|
||||
[{ to: foo, metadata: "qux-foo" }],
|
||||
)
|
||||
expect(graph.shortestPath(foo, qux) || []).toHaveLength(3)
|
||||
})
|
||||
test("bfs", () => {
|
||||
const graph = new Graph<string, string>()
|
||||
const foo = graph.addVertex("foo", [], [])
|
||||
const bar = graph.addVertex(
|
||||
"bar",
|
||||
[{ from: foo, metadata: "foo-bar" }],
|
||||
[],
|
||||
)
|
||||
const baz = graph.addVertex(
|
||||
"baz",
|
||||
[{ from: bar, metadata: "bar-baz" }],
|
||||
[],
|
||||
)
|
||||
const qux = graph.addVertex(
|
||||
"qux",
|
||||
[
|
||||
{ from: foo, metadata: "foo-qux" },
|
||||
{ from: baz, metadata: "baz-qux" },
|
||||
],
|
||||
[],
|
||||
)
|
||||
const bfs = Array.from(graph.breadthFirstSearch(foo))
|
||||
expect(bfs).toHaveLength(4)
|
||||
expect(bfs[0]).toBe(foo)
|
||||
expect(bfs[1]).toBe(bar)
|
||||
expect(bfs[2]).toBe(qux)
|
||||
expect(bfs[3]).toBe(baz)
|
||||
})
|
||||
test("reverseBfs", () => {
|
||||
const graph = new Graph<string, string>()
|
||||
const foo = graph.addVertex("foo", [], [])
|
||||
const bar = graph.addVertex(
|
||||
"bar",
|
||||
[{ from: foo, metadata: "foo-bar" }],
|
||||
[],
|
||||
)
|
||||
const baz = graph.addVertex(
|
||||
"baz",
|
||||
[{ from: bar, metadata: "bar-baz" }],
|
||||
[],
|
||||
)
|
||||
const qux = graph.addVertex(
|
||||
"qux",
|
||||
[
|
||||
{ from: foo, metadata: "foo-qux" },
|
||||
{ from: baz, metadata: "baz-qux" },
|
||||
],
|
||||
[],
|
||||
)
|
||||
const bfs = Array.from(graph.reverseBreadthFirstSearch(qux))
|
||||
expect(bfs).toHaveLength(4)
|
||||
expect(bfs[0]).toBe(qux)
|
||||
expect(bfs[1]).toBe(foo)
|
||||
expect(bfs[2]).toBe(baz)
|
||||
expect(bfs[3]).toBe(bar)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,45 +1,56 @@
|
||||
import { StartSdk } from "../StartSdk"
|
||||
import { setupManifest } from "../manifest/setupManifest"
|
||||
import { VersionInfo } from "../versionInfo/VersionInfo"
|
||||
import { VersionGraph } from "../versionInfo/setupVersionGraph"
|
||||
|
||||
export type Manifest = any
|
||||
export const sdk = StartSdk.of()
|
||||
.withManifest(
|
||||
setupManifest({
|
||||
id: "testOutput",
|
||||
title: "",
|
||||
version: "1.0:0",
|
||||
releaseNotes: "",
|
||||
license: "",
|
||||
replaces: [],
|
||||
wrapperRepo: "",
|
||||
upstreamRepo: "",
|
||||
supportSite: "",
|
||||
marketingSite: "",
|
||||
donationUrl: null,
|
||||
description: {
|
||||
short: "",
|
||||
long: "",
|
||||
},
|
||||
containers: {},
|
||||
images: {},
|
||||
volumes: [],
|
||||
assets: [],
|
||||
alerts: {
|
||||
install: null,
|
||||
update: null,
|
||||
uninstall: null,
|
||||
restore: null,
|
||||
start: null,
|
||||
stop: null,
|
||||
},
|
||||
dependencies: {
|
||||
"remote-test": {
|
||||
description: "",
|
||||
optional: false,
|
||||
s9pk: "https://example.com/remote-test.s9pk",
|
||||
setupManifest(
|
||||
{
|
||||
id: "testOutput",
|
||||
title: "",
|
||||
license: "",
|
||||
replaces: [],
|
||||
wrapperRepo: "",
|
||||
upstreamRepo: "",
|
||||
supportSite: "",
|
||||
marketingSite: "",
|
||||
donationUrl: null,
|
||||
description: {
|
||||
short: "",
|
||||
long: "",
|
||||
},
|
||||
containers: {},
|
||||
images: {},
|
||||
volumes: [],
|
||||
assets: [],
|
||||
alerts: {
|
||||
install: null,
|
||||
update: null,
|
||||
uninstall: null,
|
||||
restore: null,
|
||||
start: null,
|
||||
stop: null,
|
||||
},
|
||||
dependencies: {
|
||||
"remote-test": {
|
||||
description: "",
|
||||
optional: false,
|
||||
s9pk: "https://example.com/remote-test.s9pk",
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
VersionGraph.of(
|
||||
VersionInfo.of({
|
||||
version: "1.0.0:0",
|
||||
releaseNotes: "",
|
||||
migrations: {},
|
||||
})
|
||||
.satisfies("#other:1.0.0:0")
|
||||
.satisfies("#other:2.0.0:0"),
|
||||
),
|
||||
),
|
||||
)
|
||||
.withStore<{ storeRoot: { storeLeaf: "value" } }>()
|
||||
.build(true)
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
CheckDependenciesParam,
|
||||
ExecuteAction,
|
||||
GetConfiguredParams,
|
||||
SetDataVersionParams,
|
||||
SetMainStatus,
|
||||
} from ".././osBindings"
|
||||
import { CreateOverlayedImageParams } from ".././osBindings"
|
||||
@@ -46,6 +47,8 @@ describe("startosTypeValidation ", () => {
|
||||
restart: undefined,
|
||||
shutdown: undefined,
|
||||
setConfigured: {} as SetConfigured,
|
||||
setDataVersion: {} as SetDataVersionParams,
|
||||
getDataVersion: undefined,
|
||||
setHealth: {} as SetHealth,
|
||||
exposeForDependents: {} as ExposeForDependentsParams,
|
||||
getSslCertificate: {} as WithCallback<GetSslCertificateParams>,
|
||||
|
||||
Reference in New Issue
Block a user