Commit Graph

37686 Commits

Author SHA1 Message Date
Robert Lin
043e780590
feat/enterpriseportal: add license creation webhook (#64422)
Closes https://linear.app/sourcegraph/issue/CORE-241
Originally added in
https://github.com/sourcegraph/sourcegraph/pull/59214

This seems unused, but might be good to have for completedness-sake

## Test plan

Unit tests
2024-08-13 12:11:03 -07:00
Robert Lin
2649987bac
fix/enterpriseportal: [MUST REVERT LATER] relax scopes for write operations (#64453)
Staging this PR in case we don't find a way to unblock
https://sourcegraph.slack.com/archives/C079SAU0E72/p1723573784387739?thread_ts=1723566345.486509&cid=C079SAU0E72.
If this passes CI first, I'll roll this out to Enterprise Portal to
unblock TS/CE

This is needed because we can't roll out
https://github.com/sourcegraph/sourcegraph/pull/64450 due to a stuck
migration

## Test plan

n/a
2024-08-13 11:58:49 -07:00
Camden Cheek
3522dcf4af
Svelte: fix file tree guide lines (#64425)
I think I broke this when doing some refactoring to make the file tree
usable in the ref panel. Currently, the guide lines only go one level of
depth.
2024-08-13 10:33:34 -06:00
Robert Lin
27d0615a3d
dotcom: request write scopes for EP prod proxy (#64450)
doh

## Test plan

n/a
2024-08-13 16:14:57 +00:00
Robert Lin
adce59be48
fix/enterpriseportal: adjust job check frequency, tweak messaging (#64418)
- The time.Second frequency is too frequent to be checking if the job
should be run, I think I set this in testing
- Adjust the Slack messaging to say `Active license`
- Adjust the Slack messaging to include the Salesforce subscription ID

## Test plan

Tests
2024-08-13 09:11:08 -07:00
Keegan Carruthers-Smith
f2fa76a8fd
migrations: remove support for NoTransaction (#64432)
This is a partial revert commit of
cbd12608b5.

We added support for NoTransaction but it isn't needed anymore. In fact
avoiding transactions leads to issues like poisoning connections.

Test Plan: CI
2024-08-13 16:08:36 +00:00
William Bezuidenhout
26f14c0888
ci: set go mod tidy step timeout (#64449)
Closes DINF-198

## Test plan
CI
```
{
      "label": ":bazel:🧹 Go mod tidy",
      "key": "bazel-go-mod",
      "command": [
        "./dev/ci/bazel-gomodtidy.sh"
      ],
      "timeout_in_minutes": "5",
      "retry": {
        "automatic": [
          {
            "limit": 1,
            "exit_status": "*"
          },
          {
            "limit": 1,
            "exit_status": -1
          }
        ]
      },
      "agents": {
        "queue": "aspect-small"
      }
    },
```

## Changelog
2024-08-13 17:45:30 +02:00
Keegan Carruthers-Smith
9d2220ea33
migration: specify column for soft delete triggers (#64446)
We believe the migration to add tenant_id is failing on dotcom is due to
this trigger which runs for any possible change to a row. Instead it
only needs to run if the deleted_at column changes. So this migration
just adjusts each trigger to only run if deleted_at is changed.

We don't need to change the trigger function, since the trigger
functions only read deleted at.

If this doesn't resolve our issue, we will need to look into a statement
level trigger for all our triggers.

Test Plan: CI and then will test safely on larger instances.
2024-08-13 15:03:49 +00:00
Shivasurya
3cb7ab8c6a
Support SAST Scanning with both GHAS and Custom post processing script (#64423)
This pull request supports buildkite semgrep sast scan to work on both
GHAS and with custom post processing script. This script checks if GHAS
is enabled or not and runs the semgrep scan and process the result. This
way we could support repositories without GHAS enabled.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

- CI 🟢 
- sast scans are reported without any issues

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
- chore(security): Support SAST Scanning with both GHAS and Custom post
processing script
2024-08-13 09:43:09 -04:00
Felix Kling
9890086f94
fix(web): Show 'Find implementation' button for languages that support it (#64440)
Fixes srch-882

I noticed that the button wasn't shown anymore (neither in Svelte nor in
React). It seems that this broke when we switched from using the file
extension to getting the language(s) from the server.
The server sends back capitalized names which we compare against
lowercase IDs.

If there there is a new/modern way to find out whether a language
support 'find implementation' or not, please let me know. For the time
being this seems to be a simple fix to get it working again like it
before. Alternatively we can also compare the stylized name.

## Test plan

Hovering over a Go interface (e.g.
https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/internal/conf/server.go?L12)
shows the 'find implementations' button in the hovercard again)
2024-08-13 15:40:03 +02:00
Felix Kling
3e734549c7
fix(svelte): Fix tooltip in hovercards (#64443)
Fixes srch-744

It seems that the code for testing whether the target element is part of
the layout didn't work in hovercards because it (possibly?) runs before
the hovercard is rendered.
Moving the logic to `onMount` + `await tick()` seem to work, although
that might still be a coincidence.

## Test plan

Hovering over the 'precise' badge shows the corresponding tooltip.
2024-08-13 15:39:35 +02:00
Felix Kling
df91f98feb
fix(svelte): Show tools section in top navigation sidebar mode (#64438)
Fixes srch-901

The CSS for sidebar mode wasn't updated after introducing the tools
menu.


## Test plan

Manual visual testing.
2024-08-13 13:24:36 +00:00
Felix Kling
9667975db6
fix(svelte): Show focus style when tabbing through search query examples (#64439)
## Test plan

Manual testing.
2024-08-13 12:11:28 +00:00
Keegan Carruthers-Smith
e93b69bef2
migrations: use COMMIT AND CHAIN for tenant_id (#64431)
We dived into our go postgres driver and when executing a migration it
is executed as a "simple query". Postgres in this case automatically
wraps the collection of statements in a transaction, unless it contains
transaction statements. So our last attempt at removing the transaction
failed.

In this attempt we use COMMIT AND CHAIN after each table alter. What
this does is commit the current transaction and then starts it up again.
From the perspective of the go driver, it is as if there was only one
transaction. We then switch the migration to using a transaction to
ensure the go drivers clean up the postgres connection in case of
failure.

IE if a query manually starts a transaction and does not clean up, the
connection will be marked as broken for the next person who gets the
connection from the pool. By wrapping in go's transaction code the
connection will be properly cleaned up.

Test Plan: All continuous environments have already succeeded or failed
on this migration number. So we will manually run this again against
them with the migrator code to ensure the same code paths. If they
succeed we will keep code as is, otherwise we will rollback.

Additionally we did lots of adhoc testing to understand the
characteristics of go and transaction handling.

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-08-13 11:59:59 +00:00
Ólafur Páll Geirsson
7b1bc10a30
chore/API: speed up edit/test feedback loop for llmapi module (#64437)
Previously, it took ~6 seconds for a single edit/test/debug feedback
loop in the `llmapi` module. After this change, it's now 1-2s.

The reason the feedback loop was slow was that we depended on the
`//cmd/frontend/internal/modelconfig` target, which transitively brings
in `graphqlbackend` and all the migration code, which adds huge overhead
to Go link times. It was relatively easy to untangle this dependency so
I went ahead and removed it to boost my local feedback loop.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan
Green CI.

To measure the timing, I ran the tests, made a tiny change and ran the
tests against to measure the total time to build+test.

```
# Before
❯ time go test -timeout 30s github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi
ok  	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi	2.394s
go test -timeout 30s   4.26s user 4.73s system 166% cpu 5.393 total

# After
❯ time go test -timeout 30s github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi
ok  	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi	0.862s
go test -timeout 30s   1.20s user 1.21s system 135% cpu 1.774 total
```
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 11:48:15 +00:00
Noah S-C
d4fa539b31
Revert "chore(ci): rework build-tracker to use redis instead of in-memory store of build results" (#64436)
Reverts sourcegraph/sourcegraph#64304

Number of redis related issues cropped up live

## Test plan

CI
2024-08-13 13:22:41 +02:00
Bolaji Olajide
4d57eb1188
fix(sg): make sg gen output more readable (#64406)
Closes DINF-78

The output of `sg gen` is a bit hard to read when there's an error, this
is because the new line character `\n` isn't rendered as a new line. It
turns out the `%q` formatting directive used to quote a string doesn't
render the `\n` character as a new line.

| Before |
|---|
| ![CleanShot 2024-08-12 at 11 17
57@2x](https://github.com/user-attachments/assets/e03ec503-e437-4b68-80b3-fe34ac8848fb)
|

| After  |
|---|
| ![CleanShot 2024-08-12 at 10 53
35@2x](https://github.com/user-attachments/assets/5b7aac63-27b6-4de0-9c56-3b739f0ee0f9)
|

I also added a func to extract error messages from a bazel command to
avoid long output message when a bazel command fails and give the user
relevant messages related to the error.

| Before  |
|---|


https://github.com/user-attachments/assets/2d029ec1-5804-41bf-a675-8642e169ea80


| After  |
|---|
| ![CleanShot 2024-08-12 at 14 45
59@2x](https://github.com/user-attachments/assets/7d567fd6-de37-48aa-b2b5-03dc591fc77a)
|

## Test plan

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

* Manual testing

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 06:22:21 -05:00
Noah S-C
67f30a9d7a
chore(ci): rework build-tracker to use redis instead of in-memory store of build results (#64304)
Currently, build-tracker keeps track of consecutive build failures
through an in-memory store of failed builds. As this gets deployed more
frequently on MSP, we lose state more frequently which would result in
incorrect results. Instead, we can use redis as our external store as
well as for locking using redsync

## Test plan

Unit tests have been updated, but proper testing will require live
traffic

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 10:32:09 +00:00
Ólafur Páll Geirsson
47b66397da
feat/API: move from /api/v1 to /.api/llm (#64435)
Fixes CODY-3269

Previously, the OpenAI-compatible API endpoints had paths like
`/api/v1/chat/completions`, which went against an existing convention of
keeping all APIs under the `/.api` prefix. We have a fair amount of
internal tooling centered around the assumption that APIs have the
`/.api` prefix so this PR corrects the mistake and moves the
`/api/v1/chat/completions` endpoint to `/.api/llm/chat/completions`.

I went with the prefix `/.api/llm` since these allow clients to interact
with LLM features like `/chat/completions` or listing model information.
These APIs happen to be compatible with OpenAI APIs but I think it will
be more confusing to add something like "openai" or "openaicomptable" in
the API endpoint. We can just document on our website that these
endpoints are compatible with OpenAI clients.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

Green CI. I also manually confirmed that I was able to use an OpenAI
client to send requests to the new APIs.
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

* Moved `/api/v1/chat/completions` to `/.api/llm/chat/completions`. The
functionality is unchanged.

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 10:21:27 +00:00
Erik Seliger
6914068c8c
migrationtests: Actually run in a transaction when in test mode (#64434)
When we added a migration that actually relies on the promised property
of migrations always running inside a transaction, we noticed that the
memoryStore implementation we use in the dbtest package does not
actually start a transaction. This implements transactions for the
memorystore as well, to make it pass.

Test plan: Our migration now passes, and dbtest performance with and
without this change is the same.
2024-08-13 10:07:06 +00:00
Christoph Hegemann
a80ad938ce
fix: return all search-based results if no syntactic provenance is requested (#64330)
Closes
https://linear.app/sourcegraph/issue/GRAPH-797/return-all-search-based-results-if-syntactic-is-not-requested

Making sum-types like a caveman...

## Test plan

Manual testing via API. I can't make the web app do a search-based
usages request at the moment.
2024-08-13 10:52:56 +02:00
Ólafur Páll Geirsson
70aa6908ea
fix/API: make requests to /api/console work again (#64429)
Fixes CODY-3267

Previously, requests to `/api/` matched the new `publicrestapi` module,
which meant that requests to the GraphQL `/api/console` no longer
worked. This PR fixes the problem by narrowing the prefix-match to
`/api/v1` so that it no longer matches `/api/console`.

I kept the scope of this PR narrow and only fixed the /api/console bug.
I will share a separate RFC to seek input on the tradeoffs between
/api/v1 and /.api. I can make that change separately if there's wide
consensus in #wg-architecture that we want to keep all API endpoints
(public and internal-facing) under /.api.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

Ran `sg start minimal` and confirmed that I'm able to visit the URL
https://sourcegraph.test:3443/api/console

On the main branch, the same URL leads to a 404 page.

I also confirmed that the `/api/v1/chat/completions` endpoint still
works as expected.

```hurl
POST https://sourcegraph.test:3443/api/v1/chat/completions
Content-Type: application/json
Authorization: Bearer {{token}}
{
  "model": "anthropic::unknown::claude-3-sonnet-20240229",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Respond with \"no\" and nothing else"
        }
      ]
    }
  ],
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}
```
```sh
❯ hurl hurl-scratchpad/openai-sg.hurl
{"id":"chat-1727acdf-6850-4387-950b-2e89850071fa","choices":[{"finish_reason":"end_turn","index":0,"message":{"content":"no","role":"assistant"}}],"created":1723536215,"model":"anthropic::unknown::claude-3-sonnet-20240229","system_fingerprint":"","object":"chat.completion","usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}
```

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 10:04:40 +02:00
Julie Tibshirani
2bbd84fac4
Redis: refactor key prefixing (#64411)
Our redis `KeyValue` interface has a built-in way to prefix all keys.
This is helpful for integration tests, to contain all keys within a test
namespace.

This PR solidifies the implementation by pushing down the prefixing as
much as possible. In doing so, it fixes a bug with the `Keys()` method
where we forgot to prefix the pattern. This makes it easier to add new
methods to the interface without forgetting to add the prefix.
2024-08-13 10:13:02 +03:00
Keegan Carruthers-Smith
cbd12608b5
database: run tenant_id migration outside of a transaction (#64410)
We hit a deadlock when deploying this migration to s2. This is because
within our transaction of the migration we likely didn't obtain table
locks in the same order as a transaction in our application code.

So this commit introduces a new migration metadata field
"noTransaction". The documentation for migrator says you should create a
migration per needed transactions. However, this would require us to
create 100s of migrations. We believe the better approach is introducing
this field and barely advertising it.

When reading the code which actually runs migrations, there is no extra
logic done outside of BEGIN; run_migration; COMMIT; so this change is
safe.

We update the migrations to avoid duplicating the function name we
introduce in case something goes wrong (now that the transaction could
leak out the function name).

Test Plan: The actual migrations are tested by go test. I added a test
assertion that we don't call Transact, but to be honest that is super
sketchy. However, we couldn't actually find any test fixtures which
actually run against the DB. So that would require a much deeper
investment for how simple the code change is.

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-08-13 07:08:19 +02:00
Michael Lin
20f22d29f0
sg/cloud: fix eph cmd typo (#64427)
fixed typo. these commands are under `sg cloud eph`

## Test plan

CI
2024-08-13 06:53:07 +02:00
Jacob Pleiness
b5d7a4f598
fix(release): add minor step to internal release create command (#64377)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

This PR adds the ability to use `--type minor` when running `sg release
create` during the release process.

For the time being this step is the _same_ as `--type patch` which is
the default, however this allows us to differentiate the two types now
and prepares for when/if the two types diverge. This also clears up the
some confusion as the `sg release` command _can_ accept `--type minor`
already and one would expect that to be the choice when you are in fact
cutting a minor type.

Closes:
https://linear.app/sourcegraph/issue/REL-351/sourcegraphsourcegraph64377-fixrelease-add-minor-step-to-internal

## Test plan

Tested locally with `--type minor` tag.

```shell
➜  sourcegraph git:(08-08-jdp_release_minor-flag-addition) sg release create --version 5.6.877 --type minor
👉 [     setup] Finding release manifest in "."
   [     setup] No explicit branch name was provided, assuming current branch is the target: 08-08-jdp_release_minor-flag-addition
   [     setup] Found manifest for "sourcegraph" (github.com/sourcegraph/sourcegraph)
   [      meta] Owners: @sourcegraph/release
   [      meta] Repository: github.com/sourcegraph/sourcegraph
👉 [      vars] Variables
   [      vars] version="v5.6.877"
   [      vars] tag="5.6.877"
   [      vars] config="{\"version\":\"v5.6.877\",\"inputs\":\"\",\"type\":\"minor\"}"
   [      vars] git.branch="08-08-jdp_release_minor-flag-addition"
   [      vars] is_development="false"
.... Stuff here
   [ buildkite] Build created, see:
   [ buildkite] "https://buildkite.com/sourcegraph/sourcegraph/builds/287192"
   [      step] Step "buildkite" succeeded
```

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

Internal change, N/A

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-12 19:48:18 -04:00
Camden Cheek
a9b536cbcd
Chore: fix default value for clientSearchResultRanking (#64420)
The search clients [default to using Zoekt's
ranking](https://sourcegraph.com/github.com/sourcegraph/sourcegraph@f010787579fc0b88ef945a6cfd0091c58eefceeb/-/blob/client/web-sveltekit/src/routes/search/FileContentSearchResult.svelte?L29-29)
if this setting is unset, but it's documented as defaulting to ordering
by line number. Just fixes the default in the schema, which is only used
for documentation.
2024-08-12 22:47:08 +00:00
Varun Gandhi
74f4831aa3
chore: Replace gitserver.Client -> minimalGitserver in codenav (#64416)
In codenav, we use very few APIs from gitserver, so let's use a more
narrow interface (which we can potentially fake in the future) instead
of depending on gitserver.Client directly.
2024-08-12 16:40:36 -04:00
Keegan Carruthers-Smith
6a28eb85bb
tenant: set pprof label for tenant (#64338)
In the future this will allow us to attribute stack traces collected by
pprof to a tenant. This only sets it for the http middleware. I am
unsure how to achieve the same thing for grpc, since that uses
propogators.

Test Plan: captured a goroutine profile and saw some goroutines with a
tenant label

---------

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-08-12 19:40:26 +00:00
Keegan Carruthers-Smith
520444ef61
linters: update go-critic to latest (#64419)
I was tired of seeing this warning when running gazelle:

  gazelle: finding module path for import github.com/go-critic/go-critic/framework/linter: go: downloading github.com/go-critic/go-critic v0.11.4
  go: module github.com/go-critic/go-critic@upgrade found (v0.11.4), but does not contain package github.com/go-critic/go-critic/framework/linter

This updated go-critic to the latest version which makes the warning go
away since it now uses the new package path.

Test Plan: gazelle is happy and CI is happy
2024-08-12 21:30:49 +02:00
Robert Lin
cec288dc89
fix/enterpriseportal, fix/codygateway: zero-value durations and missing active licenses (#64378)
This change ensure we correctly handle:

1. In Enterprise Portal, where no active license is available, we return
ratelimit=0 intervalduration=0, from the source `PLAN` (as this is
determined by the lack of a plan)
2. In Cody Gateway, where intervalduration=0, we do not grant access to
that feature

## Test plan

Unit tests
2024-08-12 11:49:54 -07:00
Keegan Carruthers-Smith
3edfaa8db6
migration: make stitch tests run in 7s (#64417)
This change caches what we download from google storage.

Before this change on my desktop computer this test would timeout after
10 minutes. It now takes 4s.

Test Plan: go test ./internal/database/migration/stitch
2024-08-12 18:38:08 +00:00
Keegan Carruthers-Smith
5bc97d9f03
migration: fix stitch test cases (#64409)
These all fail and are only run outside of bazel (which is why we didn't
notice it). I believe the root cause is google getting more strict with
the URLs you pass it.

Should we consider removing these tests given no one has reported it not
working? Or should we get it working in Bazel?

Test Plan go test ./internal/database/migration/stitch/
2024-08-12 20:27:10 +02:00
Camden Cheek
1e3b643e94
Search blitz: updates for 3rd-party users (#64375)
The goal of this PR is to make search blitz usable for customers who
want to run it against their instance for continuous performance
analysis.

Specifically, this does two things:
1) Enables configuring the set of queries to run with the
`SEARCH_BLITZ_QUERY_FILE` env var
2) Packages the image in our standard format so we can publish it
2024-08-12 16:13:06 +00:00
Jacob Pleiness
59ad280fe1
feat(appliance): nodeexporter service definition (#64399)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

Relates to
https://linear.app/sourcegraph/issue/REL-80/service-definition-node-exporter

## Test plan

Golden tests included.

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-12 11:36:41 -04:00
Jacob Pleiness
72e1838b4c
fix(appliance): bypass setupenv-test for local testing if not installed (#64305)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

Bypass the requirement for
`sigs.k8s.io/controller-runtime/tools/setup-envtest` when running `go
test` in the `internal/appliance` package.

Previously running `go test` without
`sigs.k8s.io/controller-runtime/tools/setup-envtest` installed would
fail the tests that required it. This changes this behavior to instead
skip the tests requiring `setup-envtest` if the user doesn't have it
installed locally.

## Test plan

Tested locally without `setup-envtest` installed:
```shell
go test ./internal/appliance/reconciler... -v
=== RUN   TestApplianceTestSuite
    helpers_test.go:37: setup-envtest is not installed, skipping ApplianceTestSuite
--- SKIP: TestApplianceTestSuite (0.00s)
PASS
ok  	github.com/sourcegraph/sourcegraph/internal/appliance/reconciler	0.907s
```

Tested locally with `setup-envtest` installed:
```shell
go test ./internal/appliance/reconciler... -v
...
        --- PASS: TestApplianceTestSuite/TestDeployWorker/worker/with-blobstore (0.25s)
        --- PASS: TestApplianceTestSuite/TestDeployWorker/worker/with-replicas (0.24s)
    --- PASS: TestApplianceTestSuite/TestDoesNotDeleteUnownedResources (0.22s)
    --- PASS: TestApplianceTestSuite/TestFrontendDeploymentRollsWhenPGSecretsChange (1.36s)
        --- PASS: TestApplianceTestSuite/TestFrontendDeploymentRollsWhenPGSecretsChange/pgsql-auth (0.47s)
        --- PASS: TestApplianceTestSuite/TestFrontendDeploymentRollsWhenPGSecretsChange/codeinsights-db-auth (0.44s)
        --- PASS: TestApplianceTestSuite/TestFrontendDeploymentRollsWhenPGSecretsChange/codeintel-db-auth (0.45s)
    --- PASS: TestApplianceTestSuite/TestFrontendDeploymentRollsWhenRedisSecretsChange (0.93s)
        --- PASS: TestApplianceTestSuite/TestFrontendDeploymentRollsWhenRedisSecretsChange/redis-cache (0.45s)
        --- PASS: TestApplianceTestSuite/TestFrontendDeploymentRollsWhenRedisSecretsChange/redis-store (0.48s)
    --- PASS: TestApplianceTestSuite/TestMergeK8sObjects (0.00s)
        --- PASS: TestApplianceTestSuite/TestMergeK8sObjects/Successful_merge (0.00s)
        --- PASS: TestApplianceTestSuite/TestMergeK8sObjects/Merge_with_overlapping_keys (0.00s)
        --- PASS: TestApplianceTestSuite/TestMergeK8sObjects/Merge_with_empty_new_object (0.00s)
        --- PASS: TestApplianceTestSuite/TestMergeK8sObjects/merges_annotations (0.00s)
    --- PASS: TestApplianceTestSuite/TestNonNamespacedResourcesRemainWhenDisabled (0.45s)
    --- PASS: TestApplianceTestSuite/TestResourcesDeletedWhenDisabled (0.45s)
    --- PASS: TestApplianceTestSuite/TestStandardFeatures (2.43s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/blobstore-with-named-storage-class (0.24s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/frontend-with-no-cpu-memory-resources (0.25s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/precise-code-intel-with-env-vars (0.24s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/redis-with-multiple-custom-images (0.25s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/redis-with-storage (0.25s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/repo-updater-with-no-resources (0.26s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/repo-updater-with-pod-template-config (0.23s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/repo-updater-with-resources (0.25s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/repo-updater-with-sa-annotations (0.24s)
        --- PASS: TestApplianceTestSuite/TestStandardFeatures/standard/symbols-with-custom-image (0.23s)
PASS
ok  	github.com/sourcegraph/sourcegraph/internal/appliance/reconciler	20.576s
```

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog
N/A as this is not a user facing change.
<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-12 11:27:36 -04:00
Jean-Hadrien Chabran
991355ba02
chore(ci): shard authz test (#64413)
Similar to https://github.com/sourcegraph/sourcegraph/pull/64412 

## Test plan

CI
2024-08-12 14:50:01 +00:00
Jean-Hadrien Chabran
4d21a3e68f
chore(ci): shard //internal/repos:repos_test (#64412)
See
https://buildkite.com/organizations/sourcegraph/analytics/suites/sourcegraph-bazel/tests/d047e8dd-c849-8a8b-8925-41c2b8e58ec9?branch=main,
this particular test target tends to timeout on occasions, because it
goes over the `short` timeout.

By sharding it, we could hope it would be more stable. So, time will
tell if that was worth it. Right now, analytics shows that it goes down
to 10s with four shards, which is faster that most runs.

## Test plan

CI
2024-08-12 14:39:29 +00:00
Keegan Carruthers-Smith
f517373f22
tenant: pprof for missing tenant in FromContext (#64405)
Instead of adding instrumentation for each place we expect a tenant, we
instead assume that we always expect a tenant if FromContext is called.
This should allow us to not miss any places.

Note: this does remove the logging we had in diskcache, but it seems
more reasonable to just use pprof for something that can be noisy?

Test Plan: just gonna rely on CI since this defaults to off.
2024-08-12 13:00:03 +00:00
Julie Tibshirani
e65e736cb1
Redis: simplify DeleteAllKeysWithPrefix (#64407)
The `DeleteAllKeysWithPrefix` method is now only used in tests to ensure
the test keyspace is clear. This PR makes it clear this method is only
used in tests, and simplifies the implementation so it no longer needs a
script + direct Redis connection.

Another tiny Redis refactor to prepare for multi-tenancy work.
2024-08-12 15:25:33 +03:00
Julie Tibshirani
fae95fdf13
Search: boost phrases in hybrid search (#64367)
This PR passes the 'boost' annotation down to searcher, so that it can
apply phrase boosting. For now, we just pass the boost to the Zoekt
query in hybrid search, which already gives a nice benefit since the
Zoekt results are streamed back first.

Note: this doesn't completely implement boosting in searcher, but it was
really simple and seemed worth it. We're purposefully not investing in
big searcher ranking improvements, since we think a better investment is
to unify logic across Zoekt + searcher.
2024-08-12 11:24:51 +03:00
Robert Lin
02ac0214ee
chore/enterpriseportal: manual E2E test suite (#64057)
Adds a super simple E2E test suite that must be run with `sg test
enterprise-portal-e2e` against a locally running Enterprise Portal
instance. This is not intended to be filled with super granular
assertions - it simply tests that everything is wired up correctly and
runs end-to-end.

Caught at ~3 issues with this already, amended various downstack PRs
with the fix 😆

Closes
https://linear.app/sourcegraph/issue/CORE-229/enterprise-portal-basic-manual-e2e-testing-setup

## Test plan

```
sg start dotcom
sg test enterprise-portal-e2e
```

No additional configuration required, the defaults work as-is
2024-08-09 19:37:52 -07:00
Robert Lin
082535836a
feat/enterpriseportal: add instance category (#64253)
Per some feedback around
https://docs.google.com/document/d/1NyBIQvZ-ziNhiz7Yuzbp4f72Gp6EUrVUoBYnnnviXi8/edit,
this adds a "instance type" enumeration for each subscription:

1. PRIMARY: production
2. SECONDARY: dev/testing/staging/whatever
3. INTERNAL: for us

## Test plan

Updated tests
2024-08-09 18:19:51 -07:00
Robert Lin
e2c646ad92
feat/enterpriseportal: all subscriptions APIs use enterprise portal DB (#63959)
This change follows
https://github.com/sourcegraph/sourcegraph/pull/63858 by making the
_all_ subscriptions APIs read and write to the Enterprise Portal
database, instead of dotcomdb, using the data that we sync from dotcomdb
into Enterprise Portal.

With this PR, all initially proposed subscriptions APIs are at least
partially implemented.

Uses https://github.com/hexops/valast/pull/27 for custom `autogold`
rendering of `utctime.Time`

Closes https://linear.app/sourcegraph/issue/CORE-156
Part of https://linear.app/sourcegraph/issue/CORE-158

## Test plan

- [x] Unit tests on API level
- [x] Adapters unit testing
- [x] Simple E2E test:
https://github.com/sourcegraph/sourcegraph/pull/64057
2024-08-09 17:26:18 -07:00
Felix Kling
8296e9804f
feat(svelte): Migrate dotcom community search pages to Svelte (#64388)
What: This PR does the bare minimum to migrate the current community
search pages to Svelte. A better strategy for managing them is needed in
the medium/long term.

How: The community pages live at the root (e.g. `/kubernetes`) which
complicates things, but I'll get to that later. The page is implemented
as a single parameterized route. A parameter matcher is used to validate
the community name. Because these pages should only be accessible on
dotcom the matcher also validates whether or not we are on dotcom (if
not, the path will be matched against a different route).

The page config is stored in a separate module so that it's no included
in every page and so that it can be used in the integration test.

The loader and page implementation themselves are straightforward. I
made a couple of changes in other modules to make implementation easier:

- Extracted the parameter type of the `marked` function so that it can
be used as prop type.
- Added an `inline` option to `marked` that allows formatting markdown
as 'inline', i.e. without `p` wrapper.
- Added a `wrap` prop to `SyntaxHighlightedQuery.svelte` to configure
line wrapping of syntax highlighted search queries (instead of having to
overwrite styles with `:global`).
- Extended the route code generator to be able to handle single
parameter segments and the `communitySearchContext` matcher.

Because the community routes should only be available on dotcom I added
a new tag to the code generator that allows it include routes only for
dotcom.
Once we change how all this works and have community search pages live
under a different path we can simplify this again.

Result:

| React | Svelte |
|--------|--------|
|
![2024-08-09_16-05](https://github.com/user-attachments/assets/a64c4e0c-a9dd-4248-9466-05b348559408)
|
![2024-08-09_16-04](https://github.com/user-attachments/assets/d8ad424b-d04a-4590-b198-a6b2f4a76816)
|


## Test plan

- New integration tests.
- Verified that `/kubernetes` shows a 'repo not found error' when
running against S2.
- Verified that `/kubernetes` shows the community page when running
against dotcom.
- Verified that `window.context.svelteKit.enabledRoutes` contains the
community page route in enterprise mode but not in dotcom mode.
2024-08-09 22:52:47 +02:00
Camden Cheek
f1060eccac
Svelte: add support for navigating search results with the keyboard (#64257)
This adds support for navigating between search results with keyboard
shortcuts. Similar to the React app, `j` or `down` means "next result",
and `k` or `up` means previous results. To accompany this change, when a
search is submitted, the first result is focused by default to
facilitate iterating over results with the keyboard.
2024-08-09 14:24:05 -06:00
Camden Cheek
3df76cb173
Explore panel: more granular file tree (#64372)
The first version of the file tree for the revision panel had flat file
names. This meant that files were not organized, they were very
horizontal-space-sensitive, and you could not filter to a directory
(only repo and file name).

This updates the file filter to be a full tree, which I find much easier
to use.
2024-08-09 17:14:09 +00:00
Robert Lin
0de249daf9
feat/enterpriseportal: more list options for subscriptions and licenses (#64114)
Required to build an updated subscriptions management UI.

Most of the diff is generated proto for some reason

Closes https://linear.app/sourcegraph/issue/CORE-226

## Test plan

Integration tests
2024-08-09 16:43:39 +00:00
Taras Yemets
14a4d7ce31
fix(cody): filter out deprecated models (#64381) 2024-08-09 16:37:42 +00:00
Robert Lin
8537000f9d
feat/enterpriseportal: existing subscriptions read APIs use enterprise portal DB (#63927)
This change follows
https://github.com/sourcegraph/sourcegraph/pull/63858 by making the
existing subscriptions APIs _read_ from the Enterprise Portal database,
instead of dotcomdb, using the data that we sync from dotcomdb into
Enterprise Portal.

Part of https://linear.app/sourcegraph/issue/CORE-156
Part of https://linear.app/sourcegraph/issue/CORE-158

## Test plan

Updated unit and integration tests
2024-08-09 09:36:40 -07:00