Skip to content

Commit 1268341

Browse files
committed
Fix bug with metrics
1 parent a4412a4 commit 1268341

5 files changed

Lines changed: 15 additions & 5 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ jobs:
7979
mise.toml \
8080
playground-tests \
8181
'pkg/cli/playground*' \
82+
pkg/cli/playground \
8283
pkg/cli/root.go; then
8384
echo "changed=false" >> "$GITHUB_OUTPUT"
8485
else

pkg/cli/playground/lib/state/runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export function applyMetric(metrics, name, value, mode) {
5555
if (metricMode === "increment") {
5656
const previous = Number(next[name] ?? 0);
5757
const delta = Number(value);
58-
if (!Number.isFinite(previous) || !Number.isFinite(delta)) return metrics ?? current;
58+
if (!Number.isFinite(previous) || !Number.isFinite(delta)) return metrics;
5959
next[name] = previous + delta;
6060
} else if (metricMode === "append") {
61-
if (valueLength(value) > MAX_METRIC_ITEMS_TEXT) return metrics ?? current;
61+
if (valueLength(value) > MAX_METRIC_ITEMS_TEXT) return metrics;
6262
const existing = next[name];
6363
const values = Array.isArray(existing)
6464
? [...existing, value]

pkg/cli/playground/playground.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ input[type="file"]::file-selector-button {
464464
min-height: 280px;
465465
}
466466
.viewer-inspector {
467+
height: 80px;
467468
min-height: 80px;
468469
}
469470
.viewer-response-body {

pkg/cli/playground_assets_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ import (
1313
func TestPlaygroundAssetGraphComplete(t *testing.T) {
1414
imports := regexp.MustCompile(`(?:from\s*|import\s*)["']([^"']+)["']`)
1515
styles := regexp.MustCompile(`@import\s+(?:url\()?\s*["']([^"']+)["']`)
16+
htmlAssets := regexp.MustCompile(`(?:href|src)\s*=\s*["']([^"']+)["']`)
1617
err := fs.WalkDir(playgroundUI, "playground", func(name string, entry fs.DirEntry, walkErr error) error {
1718
require.NoError(t, walkErr)
18-
if entry.IsDir() || (!strings.HasSuffix(name, ".js") && !strings.HasSuffix(name, ".css")) {
19+
if entry.IsDir() || (!strings.HasSuffix(name, ".js") && !strings.HasSuffix(name, ".css") && !strings.HasSuffix(name, ".html")) {
1920
return nil
2021
}
2122
contents, err := playgroundUI.ReadFile(name)
2223
require.NoError(t, err)
2324
patterns := []*regexp.Regexp{imports}
2425
if strings.HasSuffix(name, ".css") {
2526
patterns = []*regexp.Regexp{styles}
27+
} else if strings.HasSuffix(name, ".html") {
28+
patterns = []*regexp.Regexp{htmlAssets}
2629
}
2730
for _, pattern := range patterns {
2831
for _, match := range pattern.FindAllSubmatch(contents, -1) {
@@ -31,8 +34,8 @@ func TestPlaygroundAssetGraphComplete(t *testing.T) {
3134
continue
3235
}
3336
target := path.Clean(path.Join(path.Dir(name), reference))
34-
if strings.HasPrefix(reference, "/") {
35-
target = path.Join("playground", reference)
37+
if rootReference, ok := strings.CutPrefix(reference, "/"); ok {
38+
target = path.Join("playground", rootReference)
3639
}
3740
_, err := fs.Stat(playgroundUI, target)
3841
require.NoError(t, err, "%s references missing asset %s", name, reference)

playground-tests/trace.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ test("applies metric modes", () => {
2727
assert.deepEqual(applyMetric({ count: 2 }, "count", 3, "increment"), { count: 5 });
2828
assert.deepEqual(applyMetric({ values: [1] }, "values", 2, "append"), { values: [1, 2] });
2929
assert.deepEqual(applyMetric({ old: true }, "old", null, "replace"), {});
30+
assert.equal(applyMetric(undefined, "count", "invalid", "increment"), undefined);
31+
assert.equal(
32+
applyMetric(undefined, "values", "x".repeat(MAX_METRIC_ITEMS_TEXT + 1), "append"),
33+
undefined,
34+
);
3035
});
3136

3237
test("bounds appended metric values", () => {

0 commit comments

Comments
 (0)