Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix-quote-in-go-f…
Browse files Browse the repository at this point in the history
…f-snippit
  • Loading branch information
craigpangea committed Sep 15, 2023
2 parents 3a08c00 + d1738aa commit 958e131
Show file tree
Hide file tree
Showing 297 changed files with 7,406 additions and 3,397 deletions.
10 changes: 0 additions & 10 deletions .coveragerc

This file was deleted.

26 changes: 0 additions & 26 deletions .deepsource.toml

This file was deleted.

1 change: 0 additions & 1 deletion .environment

This file was deleted.

21 changes: 20 additions & 1 deletion .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,30 @@ jobs:
id: chunk
run: echo "chunks=$(ls cypress/e2e/* | jq --slurp --raw-input -c 'split("\n")[:-1] | _nwise(3) | join("\n")' | jq --slurp -c .)" >> $GITHUB_OUTPUT

container:
name: Build and cache container image
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [changes]
permissions:
contents: read
id-token: write # allow issuing OIDC tokens for this workflow run
steps:
- name: Checkout
if: needs.changes.outputs.shouldTriggerCypress == 'true'
uses: actions/checkout@v3
- name: Get Docker image cached in Depot
if: needs.changes.outputs.shouldTriggerCypress == 'true'
# Build the container image in preparation for the E2E tests
uses: ./.github/actions/build-n-cache-image
with:
actions-id-token-request-url: ${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }}

cypress:
name: Cypress E2E tests (${{ strategy.job-index }})
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [chunks, changes]
needs: [chunks, changes, container]
permissions:
id-token: write # allow issuing OIDC tokens for this workflow run

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/customer-data-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
images: ghcr.io/${{ steps.lowercase.outputs.repository }}/cdp

# Make the image tags used for docker cache. We use this rather than
# ${{ github.repository }} directly because the repository
# ${{ github.repository }} directly because the repository
# organization name is has upper case characters, which are not
# allowed in docker image names.
- uses: docker/metadata-action@v4
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/storybook-chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,24 @@ jobs:
if [ $ADDED -gt 0 ] || [ $MODIFIED -gt 0 ]; then
echo "Snapshots updated ($ADDED new, $MODIFIED changed), running OptiPNG"
apt update && apt install -y optipng
git add frontend/__snapshots__/ playwright/
pnpm lint-staged
optipng -clobber -o4 -strip all
# we don't want to _always_ run OptiPNG
# so, we run it after checking for a diff
# but, the files we diffed might then be changed by OptiPNG
# and as a result they might no longer be different...
# we check again
git diff --name-status frontend/__snapshots__/ # For debugging
ADDED=$(git diff --name-status frontend/__snapshots__/ | grep '^A' | wc -l)
MODIFIED=$(git diff --name-status frontend/__snapshots__/ | grep '^M' | wc -l)
DELETED=$(git diff --name-status frontend/__snapshots__/ | grep '^D' | wc -l)
TOTAL=$(git diff --name-status frontend/__snapshots__/ | wc -l)
if [ $ADDED -gt 0 ] || [ $MODIFIED -gt 0 ]; then
echo "Snapshots updated ($ADDED new, $MODIFIED changed), _even after_ running OptiPNG"
git add frontend/__snapshots__/ playwright/
fi
fi
echo "${{ matrix.browser }}-${{ matrix.shard }}-added=$ADDED" >> $GITHUB_OUTPUT
Expand Down
11 changes: 11 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ const setupMsw = () => {
// Make sure the msw worker is started
worker.start({
quiet: true,
onUnhandledRequest(request, print) {
// MSW warns on all unhandled requests, but we don't necessarily care
const pathAllowList = ['/images/']

if (pathAllowList.some((path) => request.url.pathname.startsWith(path))) {
return
}

// Otherwise, default MSW warning behavior
print.warning()
},
})
;(window as any).__mockServiceWorker = worker
;(window as any).POSTHOG_APP_CONTEXT = getStorybookAppContext()
Expand Down
4 changes: 3 additions & 1 deletion .storybook/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const LOADER_SELECTORS = [
'.LemonTableLoader',
'[aria-busy="true"]',
'.SessionRecordingPlayer--buffering',
'.Lettermark--unknown',
]

const customSnapshotsDir = `${process.cwd()}/frontend/__snapshots__`
Expand Down Expand Up @@ -207,7 +208,8 @@ async function expectLocatorToMatchStorySnapshot(
// Compare structural similarity instead of raw pixels - reducing false positives
// See https://github.com/americanexpress/jest-image-snapshot#recommendations-when-using-ssim-comparison
comparisonMethod: 'ssim',
failureThreshold: 0.0003,
// 0.01 would be a 1% difference
failureThreshold: 0.01,
failureThresholdType: 'percent',
})
}
1 change: 0 additions & 1 deletion .test_durations

This file was deleted.

10 changes: 9 additions & 1 deletion bin/plugin-server
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ if [ $? -ne 0 ]; then
exit 1
fi

[[ -n $DEBUG ]] && cmd="pnpm start:dev" || cmd="node dist/index.js"
if [[ -n $DEBUG ]]; then
if [[ -n $NO_WATCH ]]; then
cmd="pnpm start:devNoWatch"
else
cmd="pnpm start:dev"
fi
else
cmd="node dist/index.js"
fi

if [[ -n $NO_RESTART_LOOP ]]; then
echo "▶️ Starting plugin server..."
Expand Down
3 changes: 0 additions & 3 deletions codecov.yml

This file was deleted.

43 changes: 43 additions & 0 deletions cypress/e2e/notebooks-creation-and-deletion.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { randomString } from '../support/random'

function visitNotebooksList(): void {
cy.clickNavMenu('dashboards')
cy.location('pathname').should('include', '/dashboard')
cy.get('h1').should('contain', 'Dashboards & Notebooks')
cy.get('li').contains('Notebooks').should('exist').click()
}

function createNotebookAndFindInList(notebookTitle: string): void {
cy.get('[data-attr="new-notebook"]').click()
cy.get('.NotebookEditor').type(notebookTitle)

visitNotebooksList()
cy.get('[data-attr="notebooks-search"]').type(notebookTitle)
}

describe('Notebooks', () => {
beforeEach(() => {
visitNotebooksList()
})

it('can create and name a notebook', () => {
const notebookTitle = randomString('My new notebook')

createNotebookAndFindInList(notebookTitle)
cy.get('[data-attr="notebooks-table"] tbody tr').should('have.length', 1)
})

it('can delete a notebook', () => {
const notebookTitle = randomString('My notebook to delete')

createNotebookAndFindInList(notebookTitle)

cy.contains('[data-attr="notebooks-table"] tr', notebookTitle).within(() => {
cy.get('[aria-label="more"]').click()
})
cy.contains('.LemonButton', 'Delete').click()

// and the table updates
cy.contains('[data-attr="notebooks-table"] tr', notebookTitle).should('not.exist')
})
})
44 changes: 43 additions & 1 deletion cypress/e2e/notebooks.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ describe('Notebooks', () => {
'loadSessionRecordingsList'
)
})

cy.fixture('api/session-recordings/recording.json').then((recording) => {
cy.intercept('GET', /api\/projects\/\d+\/session_recordings\/.*\?.*/, { body: recording }).as(
'loadSessionRecording'
)
})

cy.fixture('api/notebooks/notebooks.json').then((notebook) => {
cy.intercept('GET', /api\/projects\/\d+\/notebooks\//, { body: notebook }).as('loadNotebooksList')
})

cy.fixture('api/notebooks/notebook.json').then((notebook) => {
cy.intercept('GET', /api\/projects\/\d+\/notebooks\/.*\//, { body: notebook }).as('loadNotebook')
// this means saving doesn't work but so what?
cy.intercept('PATCH', /api\/projects\/\d+\/notebooks\/.*\//, (req, res) => {
res.reply(req.body)
}).as('patchNotebook')
})

cy.clickNavMenu('dashboards')
Expand All @@ -34,7 +41,7 @@ describe('Notebooks', () => {
})

it('Insertion suggestions can be dismissed', () => {
cy.visit(urls.notebookEdit('h11RoiwV'))
cy.visit(urls.notebook('h11RoiwV'))
cy.get('.NotebookEditor').type('{enter}')

cy.get('.NotebookRecordingTimestamp--preview').should('exist')
Expand All @@ -53,4 +60,39 @@ describe('Notebooks', () => {
cy.get('.ph-recording.NotebookNode').should('be.visible')
cy.get('.NotebookRecordingTimestamp').should('contain.text', '0:00')
})

describe('text types', () => {
beforeEach(() => {
cy.get('li').contains('Notebooks').should('exist').click()
cy.get('[data-attr="new-notebook"]').click()
// we don't actually get a new notebook because the API is mocked
// so, "exit" the timestamp block we start in
cy.get('.NotebookEditor').type('{esc}{enter}{enter}')
})

it('Can add a number list', () => {
cy.get('.NotebookEditor').type('1. the first')
cy.get('.NotebookEditor').type('{enter}')
// no need to type the number now. it should be inserted automatically
cy.get('.NotebookEditor').type('the second')
cy.get('.NotebookEditor').type('{enter}')
cy.get('ol').should('contain.text', 'the first')
cy.get('ol').should('contain.text', 'the second')
// the numbered list auto inserts the next list item
cy.get('.NotebookEditor ol li').should('have.length', 3)
})

it('Can add bold', () => {
cy.get('.NotebookEditor').type('**bold**')
cy.get('.NotebookEditor p').last().should('contain.html', '<strong>bold</strong>')
})

it('Can add bullet list', () => {
cy.get('.NotebookEditor').type('* the first{enter}the second{enter}')
cy.get('ul').should('contain.text', 'the first')
cy.get('ul').should('contain.text', 'the second')
// the list auto inserts the next list item
cy.get('.NotebookEditor ul li').should('have.length', 3)
})
})
})
3 changes: 3 additions & 0 deletions docker-compose.hobby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ services:
extends:
file: docker-compose.base.yml
service: db
# Pin to postgres 12 until we have a process for pg_upgrade to postgres 15 for exsisting installations
image: ${DOCKER_REGISTRY_PREFIX:-}postgres:12-alpine
volumes:
- postgres-data:/var/lib/postgresql/data

redis:
extends:
file: docker-compose.base.yml
Expand Down
4 changes: 2 additions & 2 deletions ee/api/test/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from typing import Dict, Optional, cast

import pytz
from zoneinfo import ZoneInfo

from ee.api.test.fixtures.available_product_features import AVAILABLE_PRODUCT_FEATURES
from ee.models.license import License, LicenseManager
Expand Down Expand Up @@ -30,7 +30,7 @@ def setUpTestData(cls):
cls.license = super(LicenseManager, cast(LicenseManager, License.objects)).create(
key=cls.CONFIG_LICENSE_KEY,
plan=cls.CONFIG_LICENSE_PLAN,
valid_until=datetime.datetime(2038, 1, 19, 3, 14, 7, tzinfo=pytz.UTC),
valid_until=datetime.datetime(2038, 1, 19, 3, 14, 7, tzinfo=ZoneInfo("UTC")),
)
if hasattr(cls, "organization") and cls.organization: # type: ignore
cls.organization.available_product_features = AVAILABLE_PRODUCT_FEATURES # type: ignore
Expand Down
8 changes: 4 additions & 4 deletions ee/api/test/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from uuid import uuid4

import jwt
import pytz
from zoneinfo import ZoneInfo
from dateutil.relativedelta import relativedelta
from django.utils.timezone import now
from freezegun import freeze_time
Expand Down Expand Up @@ -377,13 +377,13 @@ def test_license_is_updated_on_billing_load(self, mock_request):
self.client.get("/api/billing-v2")
self.license.refresh_from_db()

self.license.valid_until = datetime(2022, 1, 2, 0, 0, 0, tzinfo=pytz.UTC)
self.license.valid_until = datetime(2022, 1, 2, 0, 0, 0, tzinfo=ZoneInfo("UTC"))
self.license.save()
assert self.license.plan == "scale"
TEST_clear_instance_license_cache()
license = get_cached_instance_license()
assert license.plan == "scale"
assert license.valid_until == datetime(2022, 1, 2, 0, 0, 0, tzinfo=pytz.UTC)
assert license.valid_until == datetime(2022, 1, 2, 0, 0, 0, tzinfo=ZoneInfo("UTC"))

mock_request.return_value.json.return_value = {
"license": {
Expand All @@ -396,7 +396,7 @@ def test_license_is_updated_on_billing_load(self, mock_request):
license = get_cached_instance_license()
assert license.plan == "enterprise"
# Should be extended by 30 days
assert license.valid_until == datetime(2022, 1, 31, 12, 0, 0, tzinfo=pytz.UTC)
assert license.valid_until == datetime(2022, 1, 31, 12, 0, 0, tzinfo=ZoneInfo("UTC"))

@patch("ee.api.billing.requests.get")
def test_organization_available_features_updated_if_different(self, mock_request):
Expand Down
4 changes: 2 additions & 2 deletions ee/api/test/test_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest.mock import Mock, patch

import pytest
import pytz
from zoneinfo import ZoneInfo
from dateutil.relativedelta import relativedelta
from django.utils import timezone
from django.utils.timezone import now
Expand All @@ -27,7 +27,7 @@ def test_can_list_and_retrieve_licenses(self):
self.assertEqual(response_data["results"][0]["key"], "12345::67890")
self.assertEqual(
response_data["results"][0]["valid_until"],
timezone.datetime(2038, 1, 19, 3, 14, 7, tzinfo=pytz.UTC).isoformat().replace("+00:00", "Z"),
timezone.datetime(2038, 1, 19, 3, 14, 7, tzinfo=ZoneInfo("UTC")).isoformat().replace("+00:00", "Z"),
)

retrieve_response = self.client.get(f"/api/license/{response_data['results'][0]['id']}")
Expand Down
Loading

0 comments on commit 958e131

Please sign in to comment.