Skip to content

Commit c24c25c

Browse files
committed
Revert "chore: update vendored Sourcegraph lib"
This reverts commit cca7abe.
1 parent bb4c53d commit c24c25c

31 files changed

Lines changed: 249 additions & 251 deletions

lib/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This directory contains vendored packages from `github.com/sourcegraph/sourcegra
55
## Source
66

77
- **Repository**: https://github.com/sourcegraph/sourcegraph
8-
- **Commit**: bdc2f4bb8b59f78f4fa8868b2690b673b41948d4
9-
- **Date**: 2026-06-01 07:34:50 +0100
8+
- **Commit**: 2ee2b8e77de9663b08ce5f6e5a2c7d2217ce721a
9+
- **Date**: 2025-11-17 19:49:42 -0800
1010

1111
## Updating
1212

lib/batches/batch_spec.go

Lines changed: 17 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package batches
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"strings"
76

@@ -39,31 +38,8 @@ type BatchSpec struct {
3938
TransformChanges *TransformChanges `json:"transformChanges,omitempty" yaml:"transformChanges,omitempty"`
4039
ImportChangesets []ImportChangeset `json:"importChangesets,omitempty" yaml:"importChangesets"`
4140
ChangesetTemplate *ChangesetTemplate `json:"changesetTemplate,omitempty" yaml:"changesetTemplate"`
42-
ChangesetHooks *ChangesetHooks `json:"changesetHooks,omitempty" yaml:"hooks,omitempty"`
4341
}
4442

45-
// Hooks declares side-effect actions to run at well-defined changeset
46-
// lifecycle events. Only allowed when Version is 3.
47-
type ChangesetHooks struct {
48-
OnCIFailure ChangesetHookAction `json:"onCIFailure,omitempty" yaml:"onCIFailure,omitempty"`
49-
OnMergeConflict ChangesetHookAction `json:"onMergeConflict,omitempty" yaml:"onMergeConflict,omitempty"`
50-
}
51-
52-
// HookAction is a single action attached to a changeset lifecycle event.
53-
//
54-
// Hook actions reuse the Step shape from the top-level steps block.
55-
type ChangesetHookAction struct {
56-
Steps []Step `json:"steps,omitempty" yaml:"steps,omitempty"`
57-
}
58-
59-
type changesetHookEvent string
60-
61-
// Hook event names. Kept here so callers don't pass typoed strings.
62-
const (
63-
ChangesetHookEventOnCIFailure changesetHookEvent = "onCIFailure"
64-
ChangesetHookEventOnMergeConflict changesetHookEvent = "onMergeConflict"
65-
)
66-
6743
type ChangesetTemplate struct {
6844
Title string `json:"title,omitempty" yaml:"title"`
6945
Body string `json:"body,omitempty" yaml:"body"`
@@ -114,46 +90,13 @@ func (oqor *OnQueryOrRepository) GetBranches() ([]string, error) {
11490
}
11591

11692
type Step struct {
117-
Run string `json:"run,omitempty" yaml:"run"`
118-
CodingAgent *CodingAgentStep `json:"codingAgent,omitempty" yaml:"codingAgent,omitempty"`
119-
BuildImage *BuildImageStep `json:"buildImage,omitempty" yaml:"buildImage,omitempty"`
120-
Container string `json:"container,omitempty" yaml:"container"`
121-
Image string `json:"image,omitempty" yaml:"image"`
122-
MaxAttempts int `json:"maxAttempts,omitempty" yaml:"maxAttempts,omitempty"`
123-
Env env.Environment `json:"env" yaml:"env"`
124-
Files map[string]string `json:"files,omitempty" yaml:"files,omitempty"`
125-
Outputs Outputs `json:"outputs,omitempty" yaml:"outputs,omitempty"`
126-
Mount []Mount `json:"mount,omitempty" yaml:"mount,omitempty"`
127-
If any `json:"if,omitempty" yaml:"if,omitempty"`
128-
}
129-
130-
type CodingAgentStep struct {
131-
Type string `json:"type,omitempty" yaml:"type"`
132-
Prompt string `json:"prompt,omitempty" yaml:"prompt"`
133-
}
134-
135-
type BuildImageStep struct {
136-
Run string `json:"run" yaml:"run"`
137-
BaseImage string `json:"baseImage" yaml:"baseImage"`
138-
}
139-
140-
// MarshalJSON canonicalizes the v3 `image:` field into `container:` on the
141-
// wire. Both fields exist on Step for ergonomic reasons (v3 specs use
142-
// `image:`, v1/v2 specs use `container:`), but src-cli's Step has only
143-
// `Container`. Without canonicalization, the prep-side cache key — computed
144-
// by JSON-marshaling Step — would include `image` while the executor side
145-
// (which round-trips through src-cli) would not, producing divergent keys
146-
// and silent cache misses for any v3 spec. See the regression test in
147-
// lib/batches/execution/cache.
148-
func (s Step) MarshalJSON() ([]byte, error) {
149-
// Use an alias type to avoid infinite recursion through MarshalJSON.
150-
type stepAlias Step
151-
canon := stepAlias(s)
152-
if canon.Container == "" {
153-
canon.Container = canon.Image
154-
}
155-
canon.Image = ""
156-
return json.Marshal(canon)
93+
Run string `json:"run,omitempty" yaml:"run"`
94+
Container string `json:"container,omitempty" yaml:"container"`
95+
Env env.Environment `json:"env" yaml:"env"`
96+
Files map[string]string `json:"files,omitempty" yaml:"files,omitempty"`
97+
Outputs Outputs `json:"outputs,omitempty" yaml:"outputs,omitempty"`
98+
Mount []Mount `json:"mount,omitempty" yaml:"mount,omitempty"`
99+
If any `json:"if,omitempty" yaml:"if,omitempty"`
157100
}
158101

159102
func (s *Step) IfCondition() string {
@@ -218,97 +161,33 @@ func parseBatchSpec(schema string, data []byte) (*BatchSpec, error) {
218161
return nil, err
219162
}
220163

221-
if spec.Version == 3 {
222-
// Mirror v3 `image:` into `container:` so in-memory consumers that
223-
// read step.Container (e.g. the executor transform) keep working.
224-
// JSON serialization is canonicalized separately in Step.MarshalJSON
225-
// so prep-side cache hashing matches src-cli/executor serialization.
226-
for i := range spec.Steps {
227-
spec.Steps[i].Container = spec.Steps[i].Image
228-
}
229-
}
230-
231164
var errs error
165+
232166
if len(spec.Steps) != 0 && spec.ChangesetTemplate == nil {
233167
errs = errors.Append(errs, NewValidationError(errors.New("batch spec includes steps but no changesetTemplate")))
234168
}
235169

236-
// v3 specs do not support changesetTemplate.published — publication is
237-
// driven exclusively via the batchchangeagent tools. Reject the field at
238-
// parse time.
239-
if spec.Version == 3 && spec.ChangesetTemplate != nil && spec.ChangesetTemplate.Published != nil {
240-
errs = errors.Append(errs, NewValidationError(errors.New("changesetTemplate.published is not supported in batch spec version 3; drive publication via the publish_changesets tool instead")))
241-
}
242-
243170
for i, step := range spec.Steps {
244171
for _, mount := range step.Mount {
245-
if strings.Contains(mount.Path, invalidMountCharacters) {
172+
if strings.ContainsAny(mount.Path, invalidMountCharacters) {
246173
errs = errors.Append(errs, NewValidationError(errors.Newf("step %d mount path contains invalid characters", i+1)))
247174
}
248-
if strings.Contains(mount.Mountpoint, invalidMountCharacters) {
175+
if strings.ContainsAny(mount.Mountpoint, invalidMountCharacters) {
249176
errs = errors.Append(errs, NewValidationError(errors.Newf("step %d mount mountpoint contains invalid characters", i+1)))
250177
}
251178
}
252-
if step.CodingAgent != nil && step.Run != "" {
253-
errs = errors.Append(errs, NewValidationError(errors.Newf("step %d: codingAgent and run cannot be combined in the same step", i+1)))
254-
}
255-
if step.BuildImage != nil && step.Run != "" {
256-
errs = errors.Append(errs, NewValidationError(errors.Newf("step %d: buildImage and run cannot be combined in the same step", i+1)))
257-
}
258179
for name := range step.Files {
259-
if strings.Contains(name, invalidMountCharacters) {
180+
if strings.ContainsAny(name, invalidMountCharacters) {
260181
errs = errors.Append(errs, NewValidationError(errors.Newf("step %d files target path contains invalid characters", i+1)))
261182
}
262183
}
263184
}
264185

265-
if hookErr := validateHooks(&spec); hookErr != nil {
266-
errs = errors.Append(errs, hookErr)
267-
}
268-
269186
return &spec, errs
270187
}
271188

272-
// validateHooks performs Go-level validation of spec.Hooks beyond what the
273-
// JSON schema enforces. The schema already gates `hooks:` on `version: 3` and
274-
// rejects unknown event names. We re-check the version invariant here so
275-
// non-schema callers (and any future schema drift) still fail safely, and we
276-
// run the per-step mount-character validator that the schema cannot express.
277-
func validateHooks(spec *BatchSpec) error {
278-
if spec.ChangesetHooks == nil {
279-
return nil
280-
}
281-
282-
var errs error
283-
284-
if spec.Version != 3 {
285-
errs = errors.Append(errs, NewValidationError(errors.New("batch spec hooks require version: 3")))
286-
}
287-
288-
validate := func(event changesetHookEvent, action ChangesetHookAction) {
289-
for i, step := range action.Steps {
290-
for _, mount := range step.Mount {
291-
if strings.Contains(mount.Path, invalidMountCharacters) {
292-
errs = errors.Append(errs, NewValidationError(errors.Newf(
293-
"hooks.%s step %d mount path contains invalid characters", event, i+1,
294-
)))
295-
}
296-
if strings.Contains(mount.Mountpoint, invalidMountCharacters) {
297-
errs = errors.Append(errs, NewValidationError(errors.Newf(
298-
"hooks.%s step %d mount mountpoint contains invalid characters", event, i+1,
299-
)))
300-
}
301-
}
302-
}
303-
}
304-
305-
validate(ChangesetHookEventOnCIFailure, spec.ChangesetHooks.OnCIFailure)
306-
validate(ChangesetHookEventOnMergeConflict, spec.ChangesetHooks.OnMergeConflict)
307-
308-
return errs
309-
}
310-
311-
const invalidMountCharacters = ","
189+
// docker uses Golang's `encoding/csv` library to parse arguments passed to `--mount`
190+
const invalidMountCharacters = ",\"\n\r"
312191

313192
func (on *OnQueryOrRepository) String() string {
314193
if on.RepositoriesMatchingQuery != "" {
@@ -333,6 +212,10 @@ func (e BatchSpecValidationError) Error() string {
333212
return e.err.Error()
334213
}
335214

215+
func IsValidationError(err error) bool {
216+
return errors.HasType[*BatchSpecValidationError](err)
217+
}
218+
336219
// SkippedStepsForRepo calculates the steps required to run on the given repo.
337220
func SkippedStepsForRepo(spec *BatchSpec, repoName string, fileMatches []string) (skipped map[int]struct{}, err error) {
338221
skipped = map[int]struct{}{}

lib/batches/changeset_spec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ func (d *ChangesetSpec) IsImportingExisting() bool {
203203
return d.Type() == ChangesetSpecDescriptionTypeExisting
204204
}
205205

206+
// IsBranch returns whether the description is of type
207+
// ChangesetSpecDescriptionTypeBranch.
208+
func (d *ChangesetSpec) IsBranch() bool {
209+
return d.Type() == ChangesetSpecDescriptionTypeBranch
210+
}
211+
206212
// ChangesetSpecDescriptionType tells the consumer what the type of a
207213
// ChangesetSpecDescription is without having to look into the description.
208214
// Useful in the GraphQL when a HiddenChangesetSpec is returned.

lib/batches/execution/cache/cache.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ func (key CacheKey) mountsMetadata() ([]MountMetadata, error) {
4747
return nil, nil
4848
}
4949

50+
// perRunEnvVars resolve to per-job or per-executor values that change on
51+
// every dequeue and must be stripped from cache keys. Mirrored in
52+
// sourcegraph/sourcegraph/lib/batches/execution/cache/cache.go.
53+
var perRunEnvVars = []string{
54+
"SRC_EXECUTOR_JOB_TOKEN",
55+
"SRC_EXECUTOR_JOB_ID",
56+
"SRC_EXECUTOR_NAME",
57+
}
58+
5059
// resolveStepsEnvironment returns a slice of environments for each of the steps,
5160
// containing only the env vars that are actually used.
5261
func resolveStepsEnvironment(globalEnv []string, steps []batches.Step) ([]map[string]string, error) {
@@ -64,6 +73,9 @@ func resolveStepsEnvironment(globalEnv []string, steps []batches.Step) ([]map[st
6473
if err != nil {
6574
return nil, errors.Wrapf(err, "resolving environment for step %d", i)
6675
}
76+
for _, name := range perRunEnvVars {
77+
delete(env, name)
78+
}
6779
envs[i] = env
6880
}
6981
return envs, nil
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cache
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/sourcegraph/sourcegraph/lib/batches"
10+
"github.com/sourcegraph/sourcegraph/lib/batches/env"
11+
)
12+
13+
func TestKeyer_Key_PerRunEnvVarsIgnored(t *testing.T) {
14+
var stepEnv env.Environment
15+
require.NoError(t, json.Unmarshal(
16+
[]byte(`["SRC_EXECUTOR_JOB_TOKEN", "SRC_EXECUTOR_JOB_ID", "SRC_EXECUTOR_NAME"]`),
17+
&stepEnv,
18+
))
19+
step := batches.Step{Run: "foo", Env: stepEnv}
20+
repo := batches.Repository{ID: "r", Name: "r"}
21+
22+
unset, err := (&CacheKey{Repository: repo, Steps: []batches.Step{step}, StepIndex: 0}).Key()
23+
require.NoError(t, err)
24+
resolved, err := (&CacheKey{Repository: repo, Steps: []batches.Step{step}, StepIndex: 0, GlobalEnv: []string{
25+
"SRC_EXECUTOR_JOB_TOKEN=tok",
26+
"SRC_EXECUTOR_JOB_ID=42",
27+
"SRC_EXECUTOR_NAME=executor-abc",
28+
}}).Key()
29+
require.NoError(t, err)
30+
require.Equal(t, unset, resolved)
31+
}

lib/batches/overridable/bool.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ type Bool struct {
77
rules rules
88
}
99

10+
// FromBool creates a Bool representing a static, scalar value.
11+
func FromBool(b bool) Bool {
12+
return Bool{
13+
rules: rules{simpleRule(b)},
14+
}
15+
}
16+
1017
// Value returns the bool value for the given repository.
1118
func (b *Bool) Value(name string) bool {
1219
v := b.rules.Match(name)

lib/batches/template/partial_eval.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func parseAndPartialEval(input string, ctx *StepContext) (*template.Template, er
8989
Funcs(builtins).
9090
Funcs(ctx.ToFuncMap()).
9191
Parse(input)
92+
9293
if err != nil {
9394
return nil, err
9495
}
@@ -348,7 +349,7 @@ func isTrue(val reflect.Value) (truth bool) {
348349
return val.Bool()
349350
case reflect.Complex64, reflect.Complex128:
350351
return val.Complex() != 0
351-
case reflect.Chan, reflect.Func, reflect.Pointer, reflect.Interface:
352+
case reflect.Chan, reflect.Func, reflect.Ptr, reflect.Interface:
352353
return !val.IsNil()
353354
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
354355
return val.Int() != 0

lib/batches/template/template.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package template
22

3-
import (
4-
"strings"
5-
"text/template"
6-
)
3+
import "text/template"
74

85
func New(name, tmpl, option string, ctxs ...template.FuncMap) (*template.Template, error) {
96
t := template.New(name).Delims(startDelim, endDelim)
@@ -19,7 +16,3 @@ func New(name, tmpl, option string, ctxs ...template.FuncMap) (*template.Templat
1916

2017
return t.Parse(tmpl)
2118
}
22-
23-
func ContainsTemplateAction(tmpl string) bool {
24-
return strings.Contains(tmpl, startDelim)
25-
}

lib/batches/template/templating.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ import (
1616
"github.com/sourcegraph/sourcegraph/lib/errors"
1717
)
1818

19-
const (
20-
startDelim = "${{"
21-
endDelim = "}}"
22-
)
19+
const startDelim = "${{"
20+
const endDelim = "}}"
2321

2422
var builtins = template.FuncMap{
2523
"join": strings.Join,
@@ -76,6 +74,7 @@ func ValidateBatchSpecTemplate(spec string) (bool, error) {
7674
// option "missingkey=error". See https://pkg.go.dev/text/template#Template.Option for
7775
// more.
7876
t, err := New("validateBatchSpecTemplate", spec, "missingkey=error", sfm, cstfm)
77+
7978
if err != nil {
8079
// Attempt to extract the specific template variable field that caused the error
8180
// to provide a clearer message.

lib/codeintel/upload/indexer_name.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
// is 10639 characters long.
2121
const MaxBufferSize = 128 * 1024
2222

23+
// ErrMetadataExceedsBuffer occurs when the first line of an LSIF index is too long to read.
24+
var ErrMetadataExceedsBuffer = errors.New("metaData vertex exceeds buffer")
25+
2326
// ErrInvalidMetaDataVertex occurs when the first line of an LSIF index is not a valid metadata vertex.
2427
var ErrInvalidMetaDataVertex = errors.New("invalid metaData vertex")
2528

0 commit comments

Comments
 (0)