Commit Graph

669 Commits

Author SHA1 Message Date
William Chargin 9b203e8489
Add graph merge functions (#62)
Summary:
Merging graphs will be a common operation. At a per-plugin level, it
will often be useful to build up graphs by creating many very small
graphs and then merging them together. At a cross-project level, we will
need to merge graphs across repositories to gain an understanding of how
value flows among these repositories. It’s important that the core graph
type provide useful functions for merging; this commit adds them.

Test Plan:
New unit tests added; run `yarn flow && yarn test`.

wchargin-branch: graph-merge
2018-03-02 21:35:51 -08:00
William Chargin 82dbf64a2c
Add an equality function for `Graph` (#61)
Summary:
We need this for testing graph equality: deep-equality is not sufficient
because two graphs can be logically equal even if, say, two nodes are
added in different orders.

This commit adds a dependency on `lodash.isequal` for deep equality.

Test Plan:
New unit tests added. Run `yarn flow && yarn test`.

wchargin-branch: graph-equals
2018-03-02 21:13:30 -08:00
William Chargin 5a2380d486
Move `addNode`/`addEdge` tests away from getters (#60)
Summary:
Nothing big; these were just organized wrong.

wchargin-branch: test-reorg
2018-03-02 20:46:35 -08:00
William Chargin 58410c62fa
Replace lingering `mealGraph`s in test case (#57)
Summary:
In merging #54, there was a semantic merge conflict that was not also a
textual merge conflict; this created a failure that only appeared once
that commit was merged.

We propose that to fix this in the future, we only merge commits that
are directly ahead of master.

Test Plan:
This fixes `yarn flow` and `yarn test`.

wchargin-branch: fix-merge-conflict
2018-03-02 14:16:51 -08:00
William Chargin 97446138ab
Make `Address`, `Node`, `Edge` read-only and exact (#56)
Summary:
Again: we assume these invariants, so we may as well encode them.
We should just keep in mind that non-Flow users may wantonly violate
these, so we should still code defensively.

wchargin-branch: readonly-exact
2018-03-02 13:49:34 -08:00
William Chargin f305a48391
Check for `null`/`undefined` in graph functions (#55)
Summary:
These will make nicer error functions in cases where static analysis
doesn’t detect the pollution: e.g., a user isn’t using Flow, or an
expression like `arr[0]` introduces an `undefined`.

Paired with @dandelionmane.

Test Plan:
New unit tests added. Run `yarn test`.

wchargin-branch: null-undefined-check
2018-03-02 13:47:13 -08:00
Dandelion Mané ca3502009b
Create an 'advancedMealGraph' test case (#54)
Create an 'advancedMealGraph' test case

The advancedMealGraph will be a grab-all that holds all advanced and
edge behaviors, e.g. the crab-self-referential loop, and the case
where there are multiple directed edges between the same two nodes.

Aggregating them into one test case will make it easier to test more
complex behaviors, like graph merging and serialization, on the
edge case graphs. However, it's still nice to have the simple graph
so that we can test simple things too. The specific tests for edge
case behavior are left mostly unchanged, in that they start from the
simple graph and add just the advanced feature that they want to test.
2018-03-02 13:45:52 -08:00
William Chargin cae3a92dc9
Add `getAllNodes` and `getAllEdges` functions (#53)
Summary:
Without these functions, it is not possible to meaningfully operate on
an arbitrary graph.

Paired with @dandelionmane.

Test Plan:
New unit tests included. Run `yarn flow && yarn test`.

wchargin-branch: get-all
2018-03-02 11:33:45 -08:00
William Chargin 01510ca63f
Make node and edge types exact (#51)
Summary:
We’ve realized that `u: Edge<T>` implies `u: Node<T>`. That certainly
wasn’t what we were expecting! We might want something like that
eventually, to capture the fact that valuations are themselves valuable,
but for now the type system should encode the assumptions that we’re
actually making. See also #50.

Paired with @dandelionmane.

wchargin-branch: exact-types
2018-03-02 11:31:38 -08:00
William Chargin 09156bf3f4
Promote `Graph` to a class with useful methods (#49)
Summary:
We had planned to expose our core types as simple Plain Old JavaScript
Objects, with accompanying standalone functions to act directly on these
data structures. We chose this instead of creating `class`es for the
types because it simplifies serialization interop: it obviates the need
for serialization and deserialization functions, because the code is
separated from the data entirely. Reconsidering, we now think that the
convenience benefits of using classes probably outweigh these
serialization cons. Furthermore, this design enables us to separate
ancillary data structures and caches from the raw data, presenting a
cleaner API for consumers of the data.

This commit introduces a `Graph` class and some related logic. With lots
of tests! And 100% code coverage! :-)

Paired with @dandelionmane.

Test Plan:
Run `yarn flow && yarn test` to see the new tests.

wchargin-branch: graph-class
2018-03-01 01:04:11 -08:00
William Chargin f5d486087d
Pull in-edges and out-edges up to top-level graph (#48)
Summary:
The main problem with having these fields on the node is that this
presents the illusion that the API surface area is larger than it
actually is. Clients with reference to a node object could
somewhat-reasonably expect that mutating these fields would be
sufficient to update the structure of the graph, but this isn’t the case
(as the edge objects would need to be updated, too). It’s a nice
semantic bonus, too, as edges aren’t conceptually “part of” nodes.

wchargin-branch: top-level-edges
2018-03-01 00:48:23 -08:00
William Chargin 66243a16c1
Remove weights from the weighted graph (#47)
Summary:
This is an experiment. There are a couple diffferent meanings of
“weight” in play: most prominently, weights assigned by plugins versus
those suitable for comparison among other arbitrary weights. We’re not
sure what the right thing is to put in the actual graph object, so we’re
going to think about this a bit more before adding the field back in.

wchargin-branch: remove-weights
2018-03-01 00:45:52 -08:00
William Chargin 43450f18b1
Rename `sourceId`/`destId` to `src`/`dst` (#46)
Summary:
The “ID” parts were left-over from the Great Address Migration, and we
think that abbreviations are fine here, anyway.

Test Plan:
`yarn flow && yarn test`

wchargin-branch: src-dst-rename
2018-03-01 00:32:30 -08:00
William Chargin 01df727c39
Add tiny-example-repository example data (#44)
Summary:
The sourcecred/tiny-example-repository repository stores some example
data that we can use to generate test cases. As of now, the repository
has been archived so that its state is stable. This commit checks in the
result of our scraper on the repository.

wchargin-branch: example-data
2018-02-28 20:36:18 -08:00
Dandelion Mané 9dc9d5e4f3 Change order of repositoryName and pluginName 2018-02-28 17:47:15 -08:00
Dandelion Mané 58ad1eb635 Add inEdges and outEdges for Nodes. 2018-02-28 17:47:15 -08:00
Dandelion Mané 2992a31157 Graph concept renames
- ID -> Address
- ID.name -> Address.id
- GraphEdge -> Edge
- GraphNode -> Node
2018-02-28 17:47:15 -08:00
William Chargin 791cad9059
Add conversion functions for id (#38)
Test Plan:
Run `yarn test` and note that tests pass.

wchargin-branch: id-conversion
2018-02-26 22:57:00 -08:00
Dandelion Mané bc2377448f
Move package json to root (#37)
Reorganize the code so that we have a single package.json file, which is at the root.
All source code now lives under `src`, separated into `src/backend` and `src/explorer`.

Test plan:

- run `yarn start` - it works
- run `yarn test` - it finds the tests (all in src/explorer) and they pass
- run `yarn flow` - it works. (tested with an error, that works too)
- run `yarn prettify` - it finds all the js files and writes to them
2018-02-26 22:32:23 -08:00