返回 DeepSeek-Reasonix
build_identity_packaging_test.go
根目录 / desktop / build_identity_packaging_test.go
1 package main
2
3 import (
4 "os"
5 "strings"
6 "testing"
7 )
8
9 func TestDesktopBuildLinksSharedSourceRevision(t *testing.T) {
10 // The remote protocol source-revision ldflag was removed with the Remote
11 // Workbench protocol stack; the test now asserts the shared product docs
12 // identity and the packaging-order invariant below.
13 data, err := os.ReadFile("../scripts/desktop-build.sh")
14 if err != nil {
15 t.Fatal(err)
16 }
17 script := string(data)
18 for _, want := range []string{
19 `SOURCE_REVISION="$(git -C "$ROOT" rev-parse --verify HEAD)"`,
20 `SOURCE_REVISION="$SOURCE_REVISION+dirty"`,
21 `product_docs_ldflags="-X reasonix/internal/productdocs.linkedVersion=$VERSION -X reasonix/internal/productdocs.linkedRevision=$SOURCE_REVISION"`,
22 `cli_identity_ldflags="-X main.version=$VERSION -X main.gitCommit=$GIT_COMMIT -X main.buildTimeUTC=$BUILD_TIME_UTC $product_docs_ldflags"`,
23 `ldflags="-X main.version=$VERSION -X main.channel=$CHANNEL $product_docs_ldflags"`,
24 `cli_identity_ldflags`,
25 } {
26 if !strings.Contains(script, want) {
27 t.Fatalf("desktop-build.sh does not preserve the shared build identity %q", want)
28 }
29 }
30
31 revisionIndex := strings.Index(script, `SOURCE_REVISION="$(git -C "$ROOT" rev-parse --verify HEAD)"`)
32 packagingMutationIndex := strings.Index(script, `node -e 'const fs=require("fs")`)
33 if revisionIndex < 0 || packagingMutationIndex < 0 || revisionIndex >= packagingMutationIndex {
34 t.Fatal("desktop-build.sh must capture the source revision before mutating packaging metadata")
35 }
36 }
37
37 lines GO