nsmcp::CodeUpstreamTool method compare (protected)
<instance of nsmcp::CodeUpstreamTool> compare context opts
Defined in /usr/local/ns/tcl/nsmcp/code-upstream.tcl
- Parameters:
- context (required)
- opts (required)
- Testcases:
- No testcase defined.
Source code: set name [dict get $opts name] set doc [::nsmcp::codeMetadata $name] if {$doc eq {} && [string first :: $name]==0} { set doc [::nsmcp::codeMetadata [string range $name 2 end]] } if {![dict exists $doc script]} { error "local-source-file-metadata-unavailable" } set path [string trimleft [dict get $doc script] /] set mapping [::nsmcp::codeUpstreamMapping $path [:mappings]] set local [::nsmcp::codeLocalComparable $name $doc] set localObservedAt [clock seconds] set repo [dict get $mapping repository] set file [dict get $mapping path] set ref [dict get $opts ref] if {$ref eq {}} { set ref [dict get $mapping ref] } set :requests 0 set sha [:commit $repo $ref] set source [:source $repo $sha $file] set selection [:selectDefinition $source $name $local] set candidates [:candidates $selection $local] set normalizations {} set ni 0 foreach normalization [dict get $local normalizations] { lappend normalizations $ni string $normalization incr ni } if {![dict get $selection selected]} { return [list {} object [list available boolean false comparisonPerformed boolean false reason string upstream-conditional-variant-unresolved name string $name sourceFile string $path repository string $repo upstreamPath string $file commit string $sha upstreamUrl string https://github.com/$repo/blob/$sha/$file localDefinitionSha256 string [dict get $local definitionSha256] localNormalizations array $normalizations candidateCount number [llength [dict get $selection candidates]] candidates array $candidates conditionsEvaluated boolean false selectedCandidate null {} matchingCandidateCount number [llength [dict get $selection matchingCandidates]] upstreamFixVerified boolean false limitations string {The loaded definition does not uniquely identify one literal upstream conditional variant. Conditions were not evaluated. Candidate comparisons are evidence, not proof of the active upstream implementation or a local modification.}]] } set remote [dict get $selection remote] set comparison [:comparison $local $remote] set baseline {} set status unknown-no-baseline if {[dict exists $mapping baselineRef] && [dict get $mapping baselineRef] ne {}} { set baseSha [:commit $repo [dict get $mapping baselineRef]] set baseSelection [:selectDefinition [:source $repo $baseSha $file] $name $local] if {[dict get $baseSelection selected]} { set baseCompare [:comparison $local [dict get $baseSelection remote]] set baseDict {} foreach {k t v} $baseCompare { dict set baseDict $k $v } set status [expr {[dict get $baseDict normalizedIdentical] ? "matches-configured-baseline" : "differs-from-configured-baseline"}] set baseline [list available boolean true commit string $baseSha url string https://github.com/$repo/blob/$baseSha/$file comparison object $baseCompare] } else { set status unknown-baseline-variant set baseline [list available boolean false reason string upstream-conditional-variant-unresolved commit string $baseSha url string https://github.com/$repo/blob/$baseSha/$file candidates array [:candidates $baseSelection $local]] } } # File history supplies candidates, not proof that each commit changes # this procedure or fixes the diagnosed failure. set history {} set historyAvailable true if {[catch { set records [ns_json parse [:get /repos/$repo/commits?sha=$sha&path=[ns_urlencode $file]&per_page=5 application/vnd.github+json]] set i 0 foreach record [lrange $records 0 4] { set hash [dict get $record sha] if {![regexp {^[a-f0-9]{40}$} $hash]} { error "invalid-github-commit" } set parents {} set j 0 set parentsAvailable [dict exists $record parents] if {$parentsAvailable} { foreach parent [lrange [dict get $record parents] 0 1] { set parentSha [dict get $parent sha] if {![regexp {^[a-f0-9]{40}$} $parentSha]} { error "invalid-github-commit" } lappend parents $j object [list commit string $parentSha url string https://github.com/$repo/commit/$parentSha] incr j } } set parentsComplete [expr {$parentsAvailable && [llength [dict get $record parents]]<=2}] lappend history $i object [list commit string $hash url string https://github.com/$repo/commit/$hash message string [string range [dict get $record commit message] 0 2047] parents array $parents parentsComplete boolean $parentsComplete] incr i } }]} { set historyAvailable false } set localBody [dict get $local body] set remoteBody [dict get $remote body] set first 0 set a [split $localBody \n] set b [split $remoteBody \n] while {$first<min([llength $a],[llength $b]) && [lindex $a $first] eq [lindex $b $first]} { incr first } set localExcerpt [string range [join [lrange $a [expr {max(0,$first-3)}] [expr {$first+30}]] \n] 0 8191] set remoteExcerpt [string range [join [lrange $b [expr {max(0,$first-3)}] [expr {$first+30}]] \n] 0 8191] return [list {} object [list available boolean true comparisonPerformed boolean true resolutionCacheSeconds number 60 comparisonScope string literal-source localNormalizations array $normalizations localComparisonBodySha256 string [ns_crypto::md string -digest sha256 -- [dict get $local comparisonBody]] candidateCount number [llength [dict get $selection candidates]] selectedCandidate number [:dict getdef $selection selectedCandidate 0] candidates array $candidates conditionsEvaluated boolean false server string [$context server] observedAt number [clock seconds] name string $name sourceFile string $path repository string $repo upstreamPath string $file requestedRef string $ref commit string $sha upstreamUrl string https://github.com/$repo/blob/$sha/$file localObservedAt number $localObservedAt localArguments string [dict get $local arguments] localDefinitionSha256 string [dict get $local definitionSha256] localBodySha256 string [ns_crypto::md string -digest sha256 -- $localBody] upstreamFileSha256 string [ns_crypto::md string -digest sha256 -- $source] comparison object $comparison baseline object $baseline localModificationStatus string $status upstreamFixVerified boolean false firstDifferentBodyLine number [expr {$localBody eq $remoteBody ? 0 : $first+1}] excerptStartBodyLine number [expr {max(0,$first-3)+1}] localExcerpt string $localExcerpt upstreamExcerpt string $remoteExcerpt excerptsComplete boolean [expr {$localExcerpt eq $localBody && $remoteExcerpt eq $remoteBody}] extraction object [list form string [dict get $remote form] dynamicCommands number [dict get $remote dynamicCommands] unsupportedCommands number [dict get $remote unsupportedCommands] selection string [dict get $selection selection]] recentFileCommits array $history historyAvailable boolean $historyAvailable historyLimit number 5 diskCompared boolean false limitations string {Conditional selection identifies a unique literal definition matching loaded code; it does not evaluate guards or establish the active implementation in an upstream installation. Raw identical/bodyIdentical comparisons preserve all bytes. normalizedIdentical/normalizedBodyIdentical separately account for explicitly reported NSF-generated preambles. Equality compares exact bodies and canonical argument lists, not semantics or full object state. Generated wrappers, formatting and framework versions can cause differences. A configured baseline is an administrator assertion, not verified installation provenance. File history is bounded and not procedure-specific. Excerpts may omit other changes. An upstream fix requires connecting code changes to the observed failure; commit messages alone are insufficient. No local source was uploaded and no remote code was executed.}]]XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)