Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: normalize uris when building the test tree #200887

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/vs/base/common/prefixTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export class WellDefinedPrefixTree<V> {
return this.root.children?.values() || Iterable.empty();
}

/** Inserts a new value in the prefix tree. */
insert(key: Iterable<string>, value: V): void {
this.opNode(key, n => n._value = value);
/**
* Inserts a new value in the prefix tree.
* @param onNode - called for each node as we descend to the insertion point,
* including the insertion point itself.
*/
insert(key: Iterable<string>, value: V, onNode?: (n: IPrefixTreeNode<V>) => void): void {
this.opNode(key, n => n._value = value, onNode);
}

/** Mutates a value in the prefix tree. */
Expand Down Expand Up @@ -136,7 +140,7 @@ export class WellDefinedPrefixTree<V> {
return node._value !== unset;
}

private opNode(key: Iterable<string>, fn: (node: Node<V>) => void): void {
private opNode(key: Iterable<string>, fn: (node: Node<V>) => void, onDescend?: (node: Node<V>) => void): void {
let node = this.root;
for (const part of key) {
if (!node.children) {
Expand All @@ -150,6 +154,7 @@ export class WellDefinedPrefixTree<V> {
} else {
node = node.children.get(part)!;
}
onDescend?.(node);
}

if (node._value === unset) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class MainThreadTesting extends Disposable implements MainThreadTestingSh
.then(c => c.map(u => IFileCoverage.deserialize(this.uriIdentityService, u))),
resolveFileCoverage: (i, token) => this.proxy.$resolveFileCoverage(runId, taskId, i, token)
.then(d => d.map(CoverageDetails.deserialize)),
}, token)) : undefined;
}, this.uriIdentityService, token)) : undefined;

(task.coverage as ISettableObservable<undefined | ((tkn: CancellationToken) => Promise<TestCoverage>)>).set(fn, undefined);
});
Expand Down
29 changes: 20 additions & 9 deletions src/vs/workbench/contrib/testing/common/testCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { ResourceMap } from 'vs/base/common/map';
import { IPrefixTreeNode, WellDefinedPrefixTree } from 'vs/base/common/prefixTree';
import { URI } from 'vs/base/common/uri';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { CoverageDetails, ICoveredCount, IFileCoverage } from 'vs/workbench/contrib/testing/common/testTypes';

export interface ICoverageAccessor {
Expand All @@ -20,13 +21,13 @@ export interface ICoverageAccessor {
export class TestCoverage {
private _tree?: WellDefinedPrefixTree<ComputedFileCoverage>;

public static async load(taskId: string, accessor: ICoverageAccessor, token: CancellationToken) {
public static async load(taskId: string, accessor: ICoverageAccessor, uriIdentityService: IUriIdentityService, token: CancellationToken) {
const files = await accessor.provideFileCoverage(token);
const map = new ResourceMap<FileCoverage>();
for (const [i, file] of files.entries()) {
map.set(file.uri, new FileCoverage(file, i, accessor));
}
return new TestCoverage(taskId, map);
return new TestCoverage(taskId, map, uriIdentityService);
}

public get tree() {
Expand All @@ -36,6 +37,7 @@ export class TestCoverage {
constructor(
public readonly fromTaskId: string,
private readonly fileCoverage: ResourceMap<FileCoverage>,
private readonly uriIdentityService: IUriIdentityService,
) { }

/**
Expand All @@ -57,15 +59,22 @@ export class TestCoverage {
* from child tests.
*/
public getComputedForUri(uri: URI) {
return this.tree.find(this.treePathForUri(uri));
return this.tree.find(this.treePathForUri(uri, /* canonical = */ false));
}

private buildCoverageTree() {
const tree = new WellDefinedPrefixTree<ComputedFileCoverage>();
const nodeCanonicalSegments = new Map<IPrefixTreeNode<ComputedFileCoverage>, string>();

// 1. Initial iteration
// 1. Initial iteration. We insert based on the case-erased file path, and
// then tag the nodes with their 'canonical' path segment preserving the
// original casing we were given, to avoid #200604
for (const file of this.fileCoverage.values()) {
tree.insert(this.treePathForUri(file.uri), file);
const keyPath = this.treePathForUri(file.uri, /* canonical = */ false);
const canonicalPath = this.treePathForUri(file.uri, /* canonical = */ true);
tree.insert(keyPath, file, node => {
nodeCanonicalSegments.set(node, canonicalPath.next().value as string);
});
}

// 2. Depth-first iteration to create computed nodes
Expand All @@ -81,7 +90,7 @@ export class TestCoverage {

if (node.children) {
for (const [prefix, child] of node.children) {
path.push(prefix);
path.push(nodeCanonicalSegments.get(child) || prefix);
const v = calculateComputed(path, child);
path.pop();

Expand All @@ -101,10 +110,12 @@ export class TestCoverage {
return tree;
}

private *treePathForUri(uri: URI) {
private *treePathForUri(uri: URI, canconicalPath: boolean) {
yield uri.scheme;
yield uri.authority;
yield* uri.path.split('/');

const path = !canconicalPath && this.uriIdentityService.extUri.ignorePathCasing(uri) ? uri.path.toLowerCase() : uri.path;
yield* path.split('/');
}

private treePathToUri(path: string[]) {
Expand Down Expand Up @@ -140,7 +151,7 @@ export abstract class AbstractFileCoverage {
}

constructor(coverage: IFileCoverage) {
this.uri = URI.revive(coverage.uri);
this.uri = coverage.uri;
this.statement = coverage.statement;
this.branch = coverage.branch;
this.function = coverage.function;
Expand Down